How to Remove Transparency from an Image using Java

2 min readSep 13, 2022


One easy way to remove transparency from an image is to apply an opaque white background behind the original image. That’s exactly what our Transparency Removal API does, otherwise rendering the image at the same resolution & in the same file format.

The best part? You can use this API for free (up to 800 API calls per moth) by registering a free account on our website & using the code examples provided below to install the API client & structure your API call in Java.

We can begin installing the client by adding a reference to the repository in pom.xml:


And we can wrap it up by adding a reference to the dependency in pom.xml:


Next, we can include the following imports at the top of our file:

// 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.EditApi;

And finally, we can call the function, passing through our input file path & API key where indicated in the comments:

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)
EditApi apiInstance = new EditApi();
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.editRemoveTransparency(imageFile);
} catch (ApiException e) {
System.err.println("Exception when calling EditApi#editRemoveTransparency");

After that, you’re all done — no more coding required. Easy as pie!




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