Image.PropertyItems Property
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets all the property items (pieces of metadata) stored in this Image.
public:
property cli::array <System::Drawing::Imaging::PropertyItem ^> ^ PropertyItems { cli::array <System::Drawing::Imaging::PropertyItem ^> ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Drawing.Imaging.PropertyItem[] PropertyItems { get; }
[<System.ComponentModel.Browsable(false)>]
member this.PropertyItems : System.Drawing.Imaging.PropertyItem[]
Public ReadOnly Property PropertyItems As PropertyItem()
An array of PropertyItem objects, one for each property item stored in the image.
- Attributes
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 = 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." );
}
}
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.");
}
}
Private Sub ExtractMetaData(ByVal e As PaintEventArgs)
Try
'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
font.Dispose()
Catch ex As ArgumentException
MessageBox.Show("There was an error. Make sure the path to the image file is valid.")
End Try
End Sub
If the image has no property items or if the image format does not support property items, PropertyItems returns an empty array (that is, an array of length zero).
מוצר | גירסאות |
---|---|
.NET | 8 (package-provided), 9 (package-provided) |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1 |
.NET Standard | 2.0 (package-provided) |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9 |
משוב של .NET
.NET הוא פרויקט קוד פתוח. בחר קישור כדי לספק משוב: