Image.PropertyItems 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得儲存在這個 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()
屬性值
PropertyItem 物件的陣列,針對影像中存放的每個屬性項目所組成的一個陣列。
- 屬性
範例
下列程式代碼範例示範如何使用 類別和 PropertyItems 屬性,在影像檔System.Drawing.Imaging.PropertyItem中讀取和顯示元數據。
此範例的設計目的是要使用匯入命名空間的 System.Drawing.Imaging Windows Form。 將程式代碼貼到表單中,並將路徑 fakePhoto.jpg
變更為 ,以指向系統上的圖像檔。 ExtractMetaData
在處理表單Paint的事件時呼叫 方法,傳遞e
為 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
備註
如果影像沒有屬性專案,或影像格式不支援屬性專案, PropertyItems 則會傳回空陣列 (,也就是長度為零的陣列) 。