How to Convert an Image to Bitmap (BMP) Format using Java

Cloudmersive
2 min readOct 21, 2022

When it comes to saving & displaying images in exceptionally high quality, Bitmap format should be one of the top options on your list. Like most quality-focused image formats, Bitmap doesn’t compress image data, meaning you’ll be left with a better looking & bulkier file than — for example — a JPG conversion would afford you. With our Image to BMP Conversion API, you can easily perform this conversion at scale for free — you just need to register a free account on our website (free accounts come with a limit of 800 API calls per month & zero additional commitments) and then follow instructions below to structure your API call using complementary, ready-to-run Java code examples.

Before we call the function, we first need to install the API client. To do so with Maven, let’s first add a reference to our pom.xml repository:

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

Then let’s add a reference to our pom.xml dependency:

<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v4.25</version>
</dependency>
</dependencies>

With the library compiled, let’s now add our imports and call the function:

// Import classes:
//import com.cloudmersive.client.invoker.ApiClient;
//import com.cloudmersive.client.invoker.ApiException;
//import com.cloudmersive.client.invoker.Configuration;
//import com.cloudmersive.client.invoker.auth.*;
//import com.cloudmersive.client.ConvertApi;
ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: Apikey
ApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");
Apikey.setApiKey("YOUR API KEY");
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
//Apikey.setApiKeyPrefix("Token");
ConvertApi apiInstance = new ConvertApi();
File imageFile = new File("/path/to/inputfile"); // File | Image file to perform the operation on. Common file formats such as PNG, JPEG are supported.
try {
byte[] result = apiInstance.convertToBmp(imageFile);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling ConvertApi#convertToBmp");
e.printStackTrace();
}

Simply include your API key and file path in their respective fields, and you’re good to go. Simple as that!

--

--

Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.