Save PNG in C#

In C# it’s easy to open and edit images as a Bitmap object.

If you have an Image or a Bitmap object and you want to save it to disc you need to do a couple of steps first.

This guide will walk you through the steps required to save an Image or Bitmap to disc in the JPG format and allow you to specify the compression quality.

Image Decoders

Before saving an image to disc you need to specify an Image Decoder.

These are really easy to work with in C#. Start by Copy / Pasting this little helper function in to your program. It will make all image saves easier in the future.

Now you are ready to use that helper function to save your Bitmap to a file. In this example we’ll save it as a PNG file.

How To Set the PNG Quality

Unfortunately in .net and in C# you can not specify the PNG encoding level. The “Quality” parameter above is actually ignored.

Save as JPG

If you want to save the image as a JPG and specify the compression level we have a guide for that as well.

You may want to check out our other C# Image Processing Guides while you’re here.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.