How to get image information in Java
2 min readFeb 13, 2020
Today we are going to show you how to retrieve image information with Java in just a few short minutes. Let’s get started.
First order of business, installing our library. Since we will employ Jitpack for this purpose, we simply need to add some references to Maven POM.
Repositories reference.
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Dependencies reference.
<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v3.34</version>
</dependency>
</dependencies>
Moving on, we now need to call our convertImageGetImageInfo function and provide an inputFile.
// 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.ConvertImageApi;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");ConvertImageApi apiInstance = new ConvertImageApi();File inputFile = new File("/path/to/file"); // File | Input file to perform the operation on.try {GetImageInfoResult result = apiInstance.convertImageGetImageInfo(inputFile);System.out.println(result);} catch (ApiException e) {System.err.println("Exception when calling ConvertImageApi#convertImageGetImageInfo");e.printStackTrace();}
And that’s all there was to it. Here is how your return will be presented, which will also show you what kind of information you shall receive.
{
"Successful": true,
"ColorSpace": "string",
"ColorType": "string",
"Width": 0,
"Height": 0,
"CompressionLevel": 0,
"ImageHashSignature": "string",
"HasTransparency": true,
"MimeType": "string",
"ImageFormat": "string",
"DPIUnit": "string",
"DPI": 0,
"ColorCount": 0,
"BitDepth": 0,
"Comment": "string",
"ExifProfileName": "string",
"ExifValues": [
{
"Tag": "string",
"DataType": "string",
"DataValue": "string"
}
]
}