How to get image information in C# .NET Framework
Today, let’s take a look at how to obtain general information from an image file, information such as format, transparency information, EXIF data, DPI, etc. Rather than the more orthodox approach of coding this out from scratch, we will instead be cutting a corner to finish up in record time.
Before we can use our API we must, of course, install its client. Activate this command in the console of Package Manager:
Install-Package Cloudmersive.APIClient.NET.DocumentAndDataConvert -Version 2.2.0
Now we just have to call the function we need, ConvertImageGetImageInfo. Here is the code you will need to accomplish this.
using System;using System.Diagnostics;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Api;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Client;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Model;namespace Example{public class ConvertImageGetImageInfoExample{public void main(){// Configure API key authorization: ApikeyConfiguration.Default.AddApiKey("Apikey", "YOUR_API_KEY");// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed// Configuration.Default.AddApiKeyPrefix("Apikey", "Bearer");var apiInstance = new ConvertImageApi();var inputFile = new System.IO.Stream(); // System.IO.Stream | Input file to perform the operation on.try{// Get information about an imageGetImageInfoResult result = apiInstance.ConvertImageGetImageInfo(inputFile);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling ConvertImageApi.ConvertImageGetImageInfo: " + e.Message );}}}}
Done! Our response will cover numerous fields, so below is a sample of its format.
{
"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"
}
]
}
