This simple tutorial provides a brief description of how to convert Bitmap to PNG in Java. It will help you to convert BMP to PNG in Java by writing a few lines of code in any of the common operating systems like Windows, macOS, and Linux. You can also set a number of attributes for the output PNG image file.
Steps to Convert Bitmap to PNG in Java
- Configure Aspose.Imaging from the Maven Repository into your project
- Load the source Bitmap file into the Image class instance for the conversion
- Initialize the PngOptions class object to set output PNG image attributes
- Set the resolution and compression level in the PngOptions class object
- Save the source Bitmap file as PNG after setting the desired attributes
In these steps, we load the source BMP file and initialize the PngOptions class instance for setting attributes of the output PNG file. Here in this step-by-step tutorial, we set the resolution and compression level in this tutorial however, other attributes can also be set before generating the PNG image. Finally, we save the BMP file to PNG in Java using the save() function of the image class.
Code to Convert BMP to PNG in Java
In this code, we used only the resolution and compression attribute to change BMP to PNG in Java. However, you can also set bit depth, color type, filter type, and XMP metadata container for the output PNG file. Note that you can load any other type of image for conversion to some other type as well.
There is no need to install any other third-party tool for this conversion. If you want to learn some other features for working with images like generating images from an Excel file, you may refer to the article on how to convert Excel chart to JPG in Java.