Cropped Bitmap To Png Stream - CSharp System.Drawing

CSharp examples for System.Drawing:PNG

Description

Cropped Bitmap To Png Stream

Demo Code


using System.Windows.Media.Imaging;
using System.Threading.Tasks;
using System.Text;
using System.Linq;
using System.IO;//from  w ww. j  ava  2  s . com
using System.Drawing.Imaging;
using System.Drawing;
using System.Collections.Generic;
using System;

public class Main{
        public static Stream CroppedBitmapToPngStream( this CroppedBitmap image )
        {
            MemoryStream memStream = new MemoryStream();
            PngBitmapEncoder encoder = new PngBitmapEncoder();

            var frame = encoder.With(x => image)
                .With(x => BitmapFrame.Create(x));
            if (frame == null)
                return null;

            encoder.Frames.Add(frame);
            encoder.Save(memStream);
            return memStream;

        }
}

Related Tutorials