get exif data from png in csharp

To get Exif data from a PNG image in C#, you can use the Image class and Image.GetPropertyItem method. Exif data is stored in a metadata tag with ID 0x8769.

Here's an example code snippet to retrieve the Exif data from a PNG image:

main.cs
using System.Drawing;
using System.Drawing.Imaging;

// Load the PNG image file
Image pngImage = Image.FromFile("image.png");

// Get the Exif metadata tag
int exifId = 0x8769;
PropertyItem exifTag = pngImage.GetPropertyItem(exifId);

// Extract the Exif data as a byte array
byte[] exifData = exifTag.Value;

// Convert the byte data to a string for display or processing
string exifString = System.Text.Encoding.ASCII.GetString(exifData);

// Cleanup resources
pngImage.Dispose();
483 chars
19 lines

related categories

gistlibby LogSnag