How to Convert BMP to WEBP with Java REST API

In this simple and easy tutorial, you’ll understand how to convert BMP to WEBP with Java REST API. BMP (or bitmap) is an image file format that stores bitmap digital images. It is widely used in Windows operating systems, where it is the standard image format. BMP files are typically uncompressed and contain a file header, bitmap information header, and raw image data. The BMP file format is capable of storing 2D digital images of various sizes, resolutions, and color depths. But, WEBP is an image file format developed by Google that uses both lossy and lossless compression to reduce file size without sacrificing image quality. It’s supported by most modern web browsers and is used to display images on the web. WEBP offers superior compression to other image formats, such as JPEG, PNG, and GIF, resulting in smaller file sizes with minimal loss of quality. If you need BMP to WEBP Conversion in Java Low Code API then this can be accomplished with the help of this sample code.

Prerequisite

Steps to Convert BMP to WEBP 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 WEBP using REST API
  7. Save the output WEBP file on local disk

Code for BMP to WEBP 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 = "BMPtoWEBP.bmp";
String outputFileName = "BMPtoWEBP.webp";
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 = "webp";
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 sample code shared above assists you to convert BMP to WEBP with Java REST API. You simply need to input BMP file with the help of the Aspose.Imaging REST API SDK and download output WEBP file to save it locally.

This BMP to WEBP Conversion feature can be put to use with any no code or low code apps on any platform.

A similar feature can be found in the following topic: How to Convert BMP to JPG with Java REST API

 English