Export (0) Print
Expand All

PropertyItem Class

Updated: September 2008

Encapsulates a metadata property to be included in an image file. Not inheritable.

Namespace:  System.Drawing.Imaging
Assembly:  System.Drawing (in System.Drawing.dll)

Public NotInheritable Class PropertyItem
Dim instance As PropertyItem

The data consists of: an identifier, the length (in bytes) of the property, the property type, and a pointer to the property value.

A PropertyItem is not intended to be used as a stand-alone object. A PropertyItem object is intended to be used by classes that are derived from Image. A PropertyItem object is used to retrieve and to change the metadata of existing image files, not to create the metadata. Therefore, the PropertyItem class does not have a defined Public constructor, and you cannot create an instance of a PropertyItem object.

To work around the absence of a Public constructor, use an existing PropertyItem object instead of creating a new instance of the PropertyItem class. For more information, see Image.GetPropertyItem.

The following code example demonstrates how to read and display the metadata in an image file using the PropertyItem class and the Image.PropertyItems property.

This example is designed to be used in 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 Sub ExtractMetaData(ByVal e As PaintEventArgs)

        'Create an Image object.  
        Dim theImage As Image = New Bitmap("c:\fakePhoto.jpg")

        'Get the PropertyItems property from image. 
        Dim propItems As PropertyItem() = theImage.PropertyItems

        'Set up the display. 
        Dim font As New font("Arial", 10)
        Dim blackBrush As New SolidBrush(Color.Black)
        Dim X As Integer = 0
        Dim Y As Integer = 0

        'For each PropertyItem in the array, display the id, type, and length. 
        Dim count As Integer = 0
        Dim propItem As PropertyItem
        For Each propItem In propItems

            e.Graphics.DrawString("Property Item " + count.ToString(), _
               font, blackBrush, X, Y)
            Y += font.Height

            e.Graphics.DrawString("   iD: 0x" & propItem.Id.ToString("x"), _
               font, blackBrush, X, Y)
            Y += font.Height

            e.Graphics.DrawString("   type: " & propItem.Type.ToString(), _
               font, blackBrush, X, Y)
            Y += font.Height

            e.Graphics.DrawString("   length: " & propItem.Len.ToString() & _
                " bytes", font, blackBrush, X, Y)
            Y += font.Height

            count += 1
        Next propItem

    Catch ex As ArgumentException
        MessageBox.Show("There was an error. Make sure the path to the image file is valid.")
    End Try 

End Sub


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0




September 2008

Added information in Remarks section based on http://support.microsoft.com/kb/821623.

Customer feedback.

Community Additions

© 2015 Microsoft