This project is read-only.

WriteableBitmap to png

May 10, 2011 at 1:57 PM

Hi,

I'm curious for an example of how to do this.

I was thinking something like this, but I can't really seem to get completed OR failed event to fire, and I assume I need to start the encoding in the Completed event.

 

 

        Stream BitmapStream;
        public void SaveImage()
        {
            MessageBox.Show("Saving image");
            Decoders.AddDecoder<PngDecoder>();
            Encoders.AddEncoder<PngEncoder>();

            ImageTools.IO.Png.PngEncoder encoder = new ImageTools.IO.Png.PngEncoder();
            ImageTools.ExtendedImage extImg = new ImageTools.ExtendedImage();
            extImg.LoadingCompleted += new EventHandler(extImg_LoadingCompleted);
            extImg.LoadingFailed += new EventHandler<UnhandledExceptionEventArgs>(extImg_LoadingFailed);

            WriteableBitmap img = new WriteableBitmap(inkP, null);
            byte[] imgBuffer = img.ToByteArray();

            BitmapStream = new MemoryStream(imgBuffer);
            extImg.SetSource(BitmapStream);
        }

May 10, 2011 at 2:14 PM

I just realized that there is an extension method, called ToImage. Clever. :)

Jan 17, 2014 at 2:11 AM
Did you want to render and convert the WriteableBitmap to png image? You sample code may be a little complex for me, and I woule like to share my bitmap to png conveting method and sample code of my image converting project.