This step by step tutorial shows you how to create PNG image from BMP in C#. This code in C# save bitmap as PNG easily and quickly. In certain situations, we need to convert bitmap to PNG in our C# applications and this sample will be helpful in such scenarios.
Steps to Create PNG Image From BMP in C#
- Setup Aspose.Imaging for .NET package from Nuget.org
- Include reference to following two namespaces: Aspose.Imaging, Aspose.Imaging.ImageOptions
- Specify license using SetLicense method before converting
- Read BMP file into an Image object
- Set attributes for output PNG image using PngOptions class
- Save the output PNG image with the specified PNG options
In the above simple steps, we’re first loading a BMP input image into an image object using Load method of Image class. Once we have loaded the BMP image into the memory, we can save it to an output PNG image. We can also specify the attributes of the output PNG image.
Code to Create PNG Image From BMP in C#
In the above code, we have set resolution of the output PNG image converted from the bitmap image. we have also set the compression level of the PNG image. Similarly, we can set other required attributes of the output image.
In our previous topic, we explained the code to convert OTG to PDF in C#. Converting between different other image formats is also similar to the sample given in the above snippet with minor changes in the code.