CSharp examples for System.Drawing:PNG
Image To Png Stream
using System.Windows.Media.Imaging; using System.Threading.Tasks; using System.Text; using System.Linq; using System.IO;/*from w w w.j a v a2s . co m*/ using System.Drawing.Imaging; using System.Drawing; using System.Collections.Generic; using System; public class Main{ public static Stream ToPngStream(this System.Windows.Controls.Image image) { if (image == null || image.Source == null) return null; MemoryStream memStream = new MemoryStream(); PngBitmapEncoder encoder = new PngBitmapEncoder(); var frame = encoder.With( x => image.Source as CroppedBitmap) .With( x => BitmapFrame.Create(x)); if (frame == null) return null; encoder.Frames.Add(frame); encoder.Save(memStream); return memStream; } }