public async Task<ExtendImageSource> InitializeAsync(CoreDispatcher dispatcher, IRandomAccessStream streamSource, CancellationTokenSource cancellationTokenSource) { byte[] bytes = new byte[streamSource.Size]; await streamSource.ReadAsync(bytes.AsBuffer(), (uint)streamSource.Size, InputStreamOptions.None).AsTask(cancellationTokenSource.Token); WriteableBitmap writeableBitmap = WebpCodec.Decode(bytes); ExtendImageSource imageSource = new ExtendImageSource(); if (writeableBitmap != null) { imageSource.PixelWidth = writeableBitmap.PixelWidth; imageSource.PixelHeight = writeableBitmap.PixelHeight; imageSource.ImageSource = writeableBitmap; } return imageSource; }
public async Task <ExtendImageSource> InitializeAsync(CoreDispatcher dispatcher, IRandomAccessStream streamSource, CancellationTokenSource cancellationTokenSource) { byte[] bytes = new byte[streamSource.Size]; await streamSource.ReadAsync(bytes.AsBuffer(), (uint)streamSource.Size, InputStreamOptions.None).AsTask(cancellationTokenSource.Token); WriteableBitmap writeableBitmap = WebpCodec.Decode(bytes); ExtendImageSource imageSource = new ExtendImageSource(); if (writeableBitmap != null) { imageSource.PixelWidth = writeableBitmap.PixelWidth; imageSource.PixelHeight = writeableBitmap.PixelHeight; imageSource.ImageSource = writeableBitmap; } return(imageSource); }
public async Task <ExtendImageSource> InitializeAsync(CoreDispatcher dispatcher, IRandomAccessStream streamSource, CancellationTokenSource cancellationTokenSource) { var inMemoryStream = new InMemoryRandomAccessStream(); var copyAction = RandomAccessStream.CopyAndCloseAsync( streamSource.GetInputStreamAt(0L), inMemoryStream.GetOutputStreamAt(0L)); await copyAction.AsTask(cancellationTokenSource.Token); var bitmapDecoder = await BitmapDecoder. CreateAsync(BitmapDecoder.GifDecoderId, inMemoryStream).AsTask(cancellationTokenSource.Token).ConfigureAwait(false); var imageProperties = await RetrieveImagePropertiesAsync(bitmapDecoder); var frameProperties = new List <FrameProperties>(); for (var i = 0u; i < bitmapDecoder.FrameCount; i++) { var bitmapFrame = await bitmapDecoder.GetFrameAsync(i).AsTask(cancellationTokenSource.Token).ConfigureAwait(false);; frameProperties.Add(await RetrieveFramePropertiesAsync(i, bitmapFrame)); } _frameProperties = frameProperties; _bitmapDecoder = bitmapDecoder; _imageProperties = imageProperties; _dispatcher = dispatcher; await _dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { CreateCanvasResources(); }); _isInitialized = true; ExtendImageSource imageSource = new ExtendImageSource(); if (_canvasImageSource != null) { imageSource.PixelWidth = _imageProperties.PixelWidth; imageSource.PixelHeight = _imageProperties.PixelHeight; imageSource.ImageSource = _canvasImageSource; } return(imageSource); }
public async Task<ExtendImageSource> InitializeAsync(CoreDispatcher dispatcher, IRandomAccessStream streamSource, CancellationTokenSource cancellationTokenSource) { var inMemoryStream = new InMemoryRandomAccessStream(); var copyAction = RandomAccessStream.CopyAndCloseAsync( streamSource.GetInputStreamAt(0L), inMemoryStream.GetOutputStreamAt(0L)); await copyAction.AsTask(cancellationTokenSource.Token); var bitmapDecoder = await BitmapDecoder. CreateAsync(BitmapDecoder.GifDecoderId, inMemoryStream).AsTask(cancellationTokenSource.Token).ConfigureAwait(false); var imageProperties = await RetrieveImagePropertiesAsync(bitmapDecoder); var frameProperties = new List<FrameProperties>(); for (var i = 0u; i < bitmapDecoder.FrameCount; i++) { var bitmapFrame = await bitmapDecoder.GetFrameAsync(i).AsTask(cancellationTokenSource.Token).ConfigureAwait(false); ; frameProperties.Add(await RetrieveFramePropertiesAsync(i, bitmapFrame)); } _frameProperties = frameProperties; _bitmapDecoder = bitmapDecoder; _imageProperties = imageProperties; _dispatcher = dispatcher; await _dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { CreateCanvasResources(); }); _isInitialized = true; ExtendImageSource imageSource = new ExtendImageSource(); if (_canvasImageSource != null) { imageSource.PixelWidth = _imageProperties.PixelWidth; imageSource.PixelHeight = _imageProperties.PixelHeight; imageSource.ImageSource = _canvasImageSource; } return imageSource; }