How to Convert JPG to BMP with Java REST API

In this short tutorial, you’ll learn how to convert JPG to BMP with Java REST API. JPG (or JPEG) is an image file format that stands for Joint Photographic Experts Group. It is the most commonly used image format for digital photographs, and is widely used for web graphics, storing digital images and photographs. JPG files are usually smaller in size than other image file formats, which makes them ideal for sharing or uploading online.

On the contrary, 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 capable of storing 2D digital images in both monochrome and color, both with and without compression. BMP files can also store digital images up to 32 bits per pixel, allowing for over 16 million colors. If you want JPG to BMP Conversion in Java Low Code API then the same can be carried out by using this code sample.

Prerequisite

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

Code for JPG 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 = "JPGtoBMP.jpg";
String outputFileName = "JPGtoBMP.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 code snippet specified above empowers you to convert JPG to BMP with Java REST API. You merely need to provide JPG file with the help of the Aspose.Imaging REST API SDK and download output BMP file to save it locally.

This JPG to BMP Conversion feature can be used with any no code or low code apps on any device or computer.

Another relevant feature can be found at the following URL: How to Convert GIF to BMP with Java REST API

 English