How to Convert an Image to PNG Format with Java

2 min readApr 28, 2022


If you’re looking for a whole bunch of Image file format conversion APIs, you’ve come to the right place. Try starting out with our PNG File Conversion API and implement easily using ready-to-run code snippets provided below in Java (installation with Maven).

To begin Java SDK installation with Maven, first add a reference to the repository in pom.xml:


After that, add one to the dependency:


Now you can add the import classes, include your Cloudmersive API key (obtainable by creating a free account on our website Home — Cloudmersive APIs), 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)
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.convertToPng(imageFile);
} catch (ApiException e) {
System.err.println("Exception when calling ConvertApi#convertToPng");




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