using System.Drawing; using System.Drawing.Imaging; // Load an image file Image image = Image.FromFile("sample.jpg"); // Get the property item ID of the ImageDescription tag int imageDescriptionID = 0x010E; // Get the property item of the ImageDescription tag PropertyItem imageDescription = image.GetPropertyItem(imageDescriptionID); // Convert the value of the property item to a string and print it string imageDescriptionValue = Encoding.UTF8.GetString(imageDescription.Value); Console.WriteLine("Image description: {0}", imageDescriptionValue);
using System.Drawing; using System.Drawing.Imaging; // Load an image file Image image = Image.FromFile("sample.jpg"); // Get the property item ID of the DateTime tag int dateTimeID = 0x0132; // Get the property item of the DateTime tag PropertyItem dateTime = image.GetPropertyItem(dateTimeID); // Convert the value of the property item to a DateTime object and print it DateTime dateTimeValue = DateTime.ParseExact(Encoding.UTF8.GetString(dateTime.Value), "yyyy:MM:dd HH:mm:ss", null); Console.WriteLine("Date taken: {0}", dateTimeValue);In this example, we load an image file and get the metadata information about the date taken using the GetPropertyItem method. We then convert the value of the property item to a DateTime object and display it on the console. Overall, the GetPropertyItem method is useful for accessing the metadata information of an image file and extracting useful information from it.