Extract Metadata from Images using C#

In simple terms, if you work with C# programming, you can use code to do things like adding, changing, deleting, or taking out information about images, like their size, shape, brand, model, and more, which is saved as data about the image.

As a C# programmer, you can also use code to get and change this image data when it’s stored in the cloud. This article will teach you how to do this 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 acquired knowledge on various aspects of working with image metadata in the cloud. You’ve learned how to seamlessly incorporate functions such as adding, editing, removing, and extracting metadata from images. Additionally, the article has elucidated the process of programmatically uploading a JPEG image file to the cloud and subsequently downloading it.

For a deeper understanding and comprehensive utilization of the GroupDocs.Metadata Manipulation Cloud API, we recommend referring to our extensive documentation. We’ve also curated an API Reference section that enables you to explore and interact with our APIs directly within your web browser.

Should you encounter any uncertainties or require further assistance, please don’t hesitate to reach out to us via our dedicated forum. We are here to assist you.

See Also