PropertyItem Class
Encapsulates a metadata property to be included in an image file. Not inheritable.
Assembly: System.Drawing (in System.Drawing.dll)
The PropertyItem type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
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: void ExtractMetaData( PaintEventArgs^ e ) { try { // Create an Image object. Image^ theImage = gcnew Bitmap( "c:\\fakePhoto.jpg" ); // Get the PropertyItems property from image. array<PropertyItem^>^propItems = theImage->PropertyItems; // Set up the display. System::Drawing::Font^ font1 = gcnew System::Drawing::Font( "Arial",10 ); SolidBrush^ blackBrush = gcnew SolidBrush( Color::Black ); int X = 0; int Y = 0; // For each PropertyItem in the array, display the id, // type, and length. int count = 0; System::Collections::IEnumerator^ myEnum = propItems->GetEnumerator(); while ( myEnum->MoveNext() ) { PropertyItem^ propItem = safe_cast<PropertyItem^>(myEnum->Current); e->Graphics->DrawString( String::Format( "Property Item {0}", count ), font1, blackBrush, (float)X, (float)Y ); Y += font1->Height; e->Graphics->DrawString( String::Format( " ID: 0x{0}", propItem->Id.ToString( "x" ) ), font1, blackBrush, (float)X, (float)Y ); Y += font1->Height; e->Graphics->DrawString( String::Format( " type: {0}", propItem->Type ), font1, blackBrush, (float)X, (float)Y ); Y += font1->Height; e->Graphics->DrawString( String::Format( " length: {0} bytes", propItem->Len ), font1, blackBrush, (float)X, (float)Y ); Y += font1->Height; count += 1; } delete font1; } catch ( Exception^ ) { MessageBox::Show( "There was an error." "Make sure the path to the image file is valid." ); } }
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
