public async Task <ImageSource> SaveToImageSource(SpiderImage spiderImage) { ImageSource imageSource = null; using (MemoryStream stream = new MemoryStream(spiderImage.Content)) { var ras = stream.AsRandomAccessStream(); var decoderGuid = BitmapDecoder.JpegDecoderId; switch (spiderImage.ImageType.ToLower()) { case "image/png": { decoderGuid = BitmapDecoder.PngDecoderId; break; } case "image/webp": { decoderGuid = BitmapDecoder.WebpDecoderId; break; } case "image/gif": { decoderGuid = BitmapDecoder.GifDecoderId; break; } } BitmapDecoder decoder = await BitmapDecoder.CreateAsync(decoderGuid, ras); var provider = await decoder.GetPixelDataAsync(); byte[] buffer = provider.DetachPixelData(); WriteableBitmap bitmap = new WriteableBitmap((int)decoder.PixelWidth, (int)decoder.PixelHeight); await bitmap.PixelBuffer.AsStream().WriteAsync(buffer, 0, buffer.Length); imageSource = bitmap; } return(imageSource); }
private async Task LoadImage() { if (imgScrollViewer.VerticalScrollBarVisibility != ScrollBarVisibility.Disabled) { imgScrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Disabled; } if (img.RenderTransform is ScaleTransform) { var transform = img.RenderTransform as ScaleTransform; transform.ScaleX = 1; transform.ScaleY = 1; } CurrentImage = ImageCollection.AsQueryable().Skip(skip).Take(take).FirstOrDefault(); if (CurrentImage == null) { skip -= 1; return; } await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, async() => { img.Source = await SaveToImageSource(CurrentImage); }); }