Extract Metadata from Images using C#

You can add, edit, remove or extract image details such as height, width, make, model, etc. stored in the form of metadata programmatically. As a C# developer, you can easily extract and manipulate the metadata information of images programmatically on the cloud. In this article, you will learn how to extract and manipulate the metadata of images using a REST API in C#.

The following topics are discussed/covered in this article:

Document Metadata Manipulation REST API and .NET SDK

For manipulating the metadata of JPEG images, I will be using the .NET SDK of GroupDocs.Metadata Cloud API. It allows you to add, edit, retrieve, and remove metadata properties from documents and image file formats. You just need to define the search criteria and the metadata Cloud REST API will take care of the specified metadata operations within supported file formats. It also provides Java SDK as its document metadata manipulation family members for the Cloud API.

You can install GroupDocs.Metadata to your Visual Studio project from the NuGet Package Manager or using the following command in the Package Manager console:

Install-Package GroupDocs.Metadata-Cloud

Please get your Client ID and Client Secret from the dashboard before you start following the steps and available code examples. Once you have your client ID and Secret, add in the code as shown below:

Add Metadata to Images using a REST API in C#

You can add metadata to images by following the simple steps given below:

Upload the Image

Firstly, upload the JPEG file on the Cloud using the code sample given below:

As a result, the uploaded JPEG image file will be available in the files section of your dashboard on the cloud.

Add Metadata to Image using C#

You can add metadata to the JPEG image programmatically by following the steps given below.

  • Create an instance of MetadataApi
  • Set the JPEG image file path in the FileInfo model
  • Define AddOptions
  • Set Value and SearchCriteria for the property using the AddProperty model
  • Create AddRequest with AddOptions
  • Get results by calling the MetadataApi.Add() method

The following code sample shows how to add metadata to a JPEG image using a REST API.

Add Metadata from Images using a REST API in C#

Add Metadata from Images using a REST API in C#

Download the Image

The above code samples will save the updated JPEG file on the cloud and can be downloaded using the following code sample:

Update Metadata of Image using C#

You can update the metadata of the JPEG image programmatically by following the steps given below.

  • Create an instance of MetadataApi
  • Set the JPEG image file path in the FileInfo model
  • Define the SetOptions
  • Set NewValue and SearchCriteria for the property using the SetProperty model
  • Create SetRequest with SetOptions
  • Get results by calling the MetadataApi.Set() method

The following code sample shows how to set metadata of a JPEG image using a REST API. Please follow the steps mentioned earlier to upload and download a file.

Update Metadata from Images using a REST API in C#

Update Metadata from Images using a REST API in C#

Remove Metadata from Image using C#

You can remove metadata from the JPEG image programmatically by following the steps given below.

  • Create an instance of MetadataApi
  • Set the JPEG image file path in the FileInfo model
  • Define RemoveOptions
  • Set the search criteria
  • Create RemoveRequest with RemoveOptions
  • Get results by calling the MetadataApi.Remove() method

The following code sample shows how to remove metadata from a JPEG image using a REST API. Please follow the steps mentioned earlier to upload and download a file.

Remove Metadata from Images using a REST API in C#

Remove Metadata from Images using a REST API in C#

Extract Metadata from Image using C#

You can extract the metadata from the JPEG image programmatically by following the steps given below.

  • Create an instance of MetadataApi
  • Set the JPEG image file path in the FileInfo model
  • Define ExtractOptions
  • Create ExtractRequest with ExtractOptions
  • Get results by calling the MetadataApi.Extract() method

The following code sample shows how to extract metadata from a JPEG image using a REST API. Please follow the steps mentioned earlier to upload a file.

Image Metadata

Image Metadata

The above code sample will produce the following output:

Package: FileFormat
FileFormat : 9
MimeType : image/jpeg
ByteOrder : 1
Width : 480
Height : 360

Package: Xmp
http://ns.microsoft.com/photo/1.0/ :

Package: Exif
Exif.GpsIfd :
Exif.ExifIfd :
Make : Canon
Model : Canon PowerShot S40
Orientation : System.Int32[]
XResolution : System.Double[]
YResolution : System.Double[]
ResolutionUnit : System.Int32[]
DateTime : 2003:12:14 12:01:44
YCbCrPositioning : System.Int32[]
ExifIfd : System.Int64[]
Exif.Thumbnail : System.Byte[] 

Try Online

Please try the following JPEG Metadata manipulation free online tool, which is developed using the above API. https://products.groupdocs.app/metadata/jpeg

Conclusion

In this article, you have learned how to add, edit, remove and extract Metadata from images on the cloud. This article also explained how to programmatically upload a JPEG image file on the cloud and download it from the cloud. You can learn even more about GroupDocs.Metadata Manipulation Cloud API using the documentation. We also provide an API Reference section that lets you visualize and interact with our APIs directly through the browser. In case of any ambiguity, please feel free to contact us on the forum.

See Also