Beispiel #1
0
		async void RenderPictures()
		{
			var service = new JDanielSmith.PictureOfTheDay.Service();
			var thickness = new Thickness(0, 0, 50, 100);

			foreach (var name in service.Names)
			{
				var image = new Image() { Stretch = Stretch.Fill, Margin = thickness };

				const int offset = 25;
				thickness = new Thickness(thickness.Left + offset, thickness.Top + offset, thickness.Right - offset, thickness.Bottom - offset);
				this.grid1.Children.Add(image);

				var result = await service.GetPictureAsync(name);

				//var bitmapImage = new BitmapImage(result.Url);
				var bitmapImage = new BitmapImage();
				// http://jebarson.info/post/2012/03/14/byte-array-to-bitmapimage-converter-irandomaccessstream-implementation-for-windows-8-metro.aspx (see comment)
				using (var ms = new Windows.Storage.Streams.InMemoryRandomAccessStream())
				{
					await result.Image.WriteContentAsync(ms.AsStreamForWrite());
					ms.Seek(0);

					await bitmapImage.SetSourceAsync(ms);
				}

				image.Source = bitmapImage;
			}
		}
		async void RenderPictures()
		{
			var service = new JDanielSmith.PictureOfTheDay.Service();
			var thickness = new Thickness(0, 0, 50, 100);

			foreach (var name in service.Names)
			{
				var image = new Image() { Stretch = Stretch.Fill, Margin = thickness };

				const int offset = 25;
				thickness = new Thickness(thickness.Left + offset, thickness.Top + offset, thickness.Right - offset, thickness.Bottom - offset);
				this.grid1.Children.Add(image);

				var result = await service.GetPictureAsync(name);
				//image.Source = new BitmapImage(result.Url);

				var bitmapImage = new BitmapImage();
				bitmapImage.BeginInit();
				bitmapImage.StreamSource = new MemoryStream();
				await result.Image.WriteContentAsync(bitmapImage.StreamSource);
				bitmapImage.EndInit();
				image.Source = bitmapImage;
			}
		}