public static async Task <BitmapHolder> ToBitmapHolderAsync(this Stream imageStream, Tuple <int, int> downscale, bool downscaleDipUnits, InterpolationMode mode, bool allowUpscale, ImageInformation imageInformation = null) { if (imageStream == null) { return(null); } using (imageStream) { if (downscale != null && (downscale.Item1 > 0 || downscale.Item2 > 0)) { WriteableBitmap downscaledImage = imageStream.ResizeImage(downscale.Item1, downscale.Item2, mode, downscaleDipUnits, allowUpscale, imageInformation); return(new BitmapHolder(await downscaledImage.ToBytesAsync(), downscaledImage.PixelWidth, downscaledImage.PixelHeight)); } BitmapDecoder decoder = NewDecoder(imageStream); BitmapFrame firstFrame = decoder.Frames.First(); firstFrame.Freeze(); if (imageInformation != null) { imageInformation.SetCurrentSize(firstFrame.PixelWidth, firstFrame.PixelHeight); imageInformation.SetOriginalSize(firstFrame.PixelWidth, firstFrame.PixelHeight); } return(new BitmapHolder(await firstFrame.ToBytesAsync(), firstFrame.PixelWidth, firstFrame.PixelHeight)); } }