Example #1
0
        public async Task <ImagePackage> InitializeAsync(CoreDispatcher dispatcher, Image image, Uri uriSource,
                                                         IRandomAccessStream streamSource,
                                                         CancellationTokenSource cancellationTokenSource)
        {
            byte[] bytes = new byte[streamSource.Size];
            await streamSource.ReadAsync(bytes.AsBuffer(), (uint)streamSource.Size, InputStreamOptions.None).AsTask(cancellationTokenSource.Token);

            int             width, height;
            WriteableBitmap writeableBitmap = null;

            if (WebpCodec.GetInfo(bytes, out width, out height))
            {
                writeableBitmap = new WriteableBitmap(width, height);
                await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    var uri = image.Tag as Uri;
                    if (uri == uriSource)
                    {
                        image.Source = writeableBitmap;
                    }
                });

                WebpCodec.Decode(writeableBitmap, bytes);
            }
            return(new ImagePackage(this, writeableBitmap, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight));
        }
Example #2
0
        public async Task <ImageSource> 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);

            var imageSource = WebpCodec.Decode(bytes);

            return(imageSource);
        }
Example #3
0
        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);
        }