Image.PropertyItems Property
Gets all the property items (pieces of metadata) stored in this Image.
Namespace: System.Drawing
Assembly: System.Drawing (in System.Drawing.dll)
Property Value
Type: System.Drawing.Imaging.PropertyItem[]An array of PropertyItem objects, one for each property item stored in the image.
The following code example demonstrates how to read and display the metadata in an image file using the System.Drawing.Imaging.PropertyItem class and the PropertyItems property.
This example is designed to be used a Windows Form that imports the System.Drawing.Imaging namespace. Paste the code into the form and change the path to fakePhoto.jpg to point to an image file on your system. Call the ExtractMetaData method when handling the form's Paint event, passing e as PaintEventArgs.
private void ExtractMetaData(PaintEventArgs e) { try { // Create an Image object. Image theImage = new Bitmap("c:\\fakePhoto.jpg"); // Get the PropertyItems property from image. PropertyItem[] propItems = theImage.PropertyItems; // Set up the display. Font font1 = new Font("Arial", 10); SolidBrush blackBrush = new SolidBrush(Color.Black); int X = 0; int Y = 0; // For each PropertyItem in the array, display the id, // type, and length. int count = 0; foreach ( PropertyItem propItem in propItems ) { e.Graphics.DrawString("Property Item " + count.ToString(), font1, blackBrush, X, Y); Y += font1.Height; e.Graphics.DrawString(" ID: 0x" + propItem.Id.ToString("x"), font1, blackBrush, X, Y); Y += font1.Height; e.Graphics.DrawString(" type: " + propItem.Type.ToString(), font1, blackBrush, X, Y); Y += font1.Height; e.Graphics.DrawString(" length: " + propItem.Len.ToString() + " bytes", font1, blackBrush, X, Y); Y += font1.Height; count += 1; } font1.Dispose(); } catch(Exception) { MessageBox.Show("There was an error." + "Make sure the path to the image file is valid."); } }
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.