How to Convert BMP to PNG with Java REST API

This quick tutorial elaborates how to convert BMP to PNG with Java REST API. A BMP file (also referred to as a bitmap image) is a raster graphics image file format used to store bitmap digital images, independently of the display device. It contains a file header, information header, and bitmap pixels, and is uncompressed. The BMP file format is capable of storing 2D digital images of arbitrary width, height, and resolution, both monochrome and color.

While, PNG (Portable Network Graphics) is a raster graphics file format that supports lossless data compression. It was designed as an improved, non-patented replacement for Graphics Interchange Format (GIF) and has become the most widely used image format on the internet. PNG supports transparency in images, and is widely used for web design, logos, icons, and other graphics. If you require BMP to PNG Conversion in Java Low Code API then the same can be achieved with the help of the following sample.

Prerequisite

Steps to Convert BMP to PNG in Java REST API

  1. Set Client ID and Client Secret for the API
  2. Create an instance of ImagingAPI class with client credentials
  3. Specify input and output files
  4. Read input BMP file and upload to cloud storage
  5. Create an instance of ConvertImageRequest with input and output file formats
  6. Call convertImage method to Convert BMP to PNG using REST API
  7. Save the output PNG file on local disk

Code for BMP to PNG Conversion in Java Low Code API

String ClientID = Client.getID(); //replace Client.getID() with your own client ID here
String ClientSecret = Client.getSecret(); //replace3 Client.getSecret() with your own client secret here
String APIBaseUrl="https://api.aspose.cloud";
String Local_Path = "C:/Temp/";
ImagingApi imagingApiSdk = new ImagingApi(ClientSecret, ClientID, APIBaseUrl);
// Input & output file names
String inputFileName = "BMPtoPNG.bmp";
String outputFileName = "BMPtoPNG.png";
try {
// Upload local image to Cloud Storage
File inputFile = new File(Local_Path + inputFileName);
FileInputStream inputFileStream = new FileInputStream(inputFile);
byte[] inputImageData = IOUtils.toByteArray(inputFileStream);
UploadFileRequest uploadFileRequest = new UploadFileRequest(inputFileName, inputImageData, null);
FilesUploadResult filesUploadResult = imagingApiSdk.uploadFile(uploadFileRequest);
String outputFormat = "png";
String remoteFolder = null; // Input file is saved at the root of the storage
String remoteStorage = null; // Cloud Storage name
ConvertImageRequest convertImageRequest = new ConvertImageRequest(inputFileName, outputFormat, remoteFolder, remoteStorage);
byte[] convertedImageData = imagingApiSdk.convertImage(convertImageRequest);
// Save exported image to local storage
FileOutputStream fileOutputStream = new FileOutputStream(Local_Path + outputFileName);
fileOutputStream.write(convertedImageData);
fileOutputStream.close();
} catch (Exception e) {
System.out.println(e.getMessage());
}

The code snippet given in this post assists you to convert BMP to PNG with Java REST API. You simply need to provide BMP file with the help of the Aspose.Imaging REST API SDK and download output PNG file to save it locally.

This BMP to PNG Conversion could be used with any no code or low code apps on any operating system.

A related feature might also be helpful to you: How to Convert BMP to PDF with Java REST API

 English