How to emboss an image in Java

Cloudmersive
2 min readJan 28, 2020

--

Embossing an image can be a really nice touch, and makes an excellent addition to any photo app or website. Getting this effect to work can take a little doing if you approach it in the traditional way. Today, however, we will be doing things a little differently, which will allow us to finish in just a few minutes. Let’s get started!

First off, we need to add two references for Jitpack in pom.xml:

Repository

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

Dependency

<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v2.75</version>
</dependency>
</dependencies>

Now we are ready to call filterEmboss and define our effect radius and sigma:

// 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.FilterApi;ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: ApikeyApiKeyAuth 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");FilterApi apiInstance = new FilterApi();Integer radius = 56; // Integer | Radius in pixels of the emboss operation; a larger radius will produce a greater effectInteger sigma = 56; // Integer | Sigma, or variance, of the emboss operationFile imageFile = new File("/path/to/file"); // File | Image file to perform the operation on.  Common file formats such as PNG, JPEG are supported.try {byte[] result = apiInstance.filterEmboss(radius, sigma, imageFile);System.out.println(result);} catch (ApiException e) {System.err.println("Exception when calling FilterApi#filterEmboss");e.printStackTrace();}

And… that’s it! No seriously, we are done. Eager to see the results? Let’s test it on this image:

Now let’s add our effect with a radius of 1 and sigma of 2:

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet