public static async Task <Stream> StreamFromRasterImage(RasterImage image) { using (RasterCodecs codecs = new RasterCodecs()) { codecs.Options.Png.Save.QualityFactor = 10; var stream = new MemoryStream(); using (var leadStream = LeadStream.Factory.FromStream(stream)) { await codecs.SaveAsync(image, leadStream, RasterImageFormat.Png, 0); stream.Seek(0, SeekOrigin.Begin); return(stream); } } }