2016-03-22 23:02:25 +03:00
|
|
|
using System;
|
|
|
|
using System.IO;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Windows.UI.Xaml.Media.Imaging;
|
|
|
|
|
|
|
|
#if WINDOWS_UWP
|
|
|
|
|
|
|
|
namespace Xamarin.Forms.Platform.UWP
|
|
|
|
#else
|
|
|
|
|
|
|
|
namespace Xamarin.Forms.Platform.WinRT
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
public sealed class StreamImagesourceHandler : IImageSourceHandler
|
|
|
|
{
|
|
|
|
public async Task<Windows.UI.Xaml.Media.ImageSource> LoadImageAsync(ImageSource imagesource, CancellationToken cancellationToken = new CancellationToken())
|
|
|
|
{
|
|
|
|
BitmapImage bitmapimage = null;
|
|
|
|
|
|
|
|
var streamsource = imagesource as StreamImageSource;
|
|
|
|
if (streamsource != null && streamsource.Stream != null)
|
|
|
|
{
|
2016-03-25 23:53:19 +03:00
|
|
|
using (Stream stream = await streamsource.GetStreamAsync(cancellationToken))
|
2016-03-22 23:02:25 +03:00
|
|
|
{
|
|
|
|
if (stream == null)
|
|
|
|
return null;
|
|
|
|
bitmapimage = new BitmapImage();
|
|
|
|
await bitmapimage.SetSourceAsync(stream.AsRandomAccessStream());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return bitmapimage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|