How to Convert PNG to BMP with Java REST API

This quick tutorial elaborates how to convert PNG to BMP with Java REST API. PNG (Portable Network Graphics) is a raster-based file format that compresses image data for websites and other online uses. The format uses lossless compression, meaning that the image quality is not compromised when the image is compressed. PNG files are often used in place of GIF and JPEG files due to their better image quality and smaller file sizes.

While, BMP (Bitmap) is an image file format used to store bitmap digital images, especially on Microsoft Windows and OS/2 operating systems. BMP files are stored in a device-independent bitmap (DIB) format, which is a raster graphics image format used to store bitmap digital images independent of the display device. BMP files are typically uncompressed, making them large in size. They are commonly used for storing digital photos and other types of images. If you require PNG to BMP Conversion in Java Low Code API then the same can be performed by using the following code snippet.

Prerequisite

Steps to Convert PNG to BMP 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 PNG file and upload to cloud storage
  5. Create an instance of ConvertImageRequest with input and output file formats
  6. Call convertImage method to Convert PNG to BMP using REST API
  7. Save the output BMP file on local disk

Code for PNG to BMP Conversion in Java Low Code API

String ClientID = Client.getID(); //replace Client.getID() with your own client ID here
String ClientSecret = Client.getSecret(); //replace 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 = "PNGtoBMP.png";
String outputFileName = "PNGtoBMP.bmp";
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 = "bmp";
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 above code snippet enables you to convert PNG to BMP with Java REST API. You simply have to provide PNG file with the help of the Aspose.Imaging REST API SDK and download output BMP file to save it locally.

This PNG to BMP Conversion could be consumed with any no code or low code apps on any platform.

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

 English