PropertyItem Klasse

Definition

Kapselt eine Metadateneigenschaft, die in eine Bilddatei aufgenommen werden soll. Kann nicht vererbt werden.

public ref class PropertyItem sealed
public sealed class PropertyItem
type PropertyItem = class
Public NotInheritable Class PropertyItem
Vererbung
PropertyItem

Beispiele

Im folgenden Codebeispiel wird veranschaulicht, wie die Metadaten in einer Bilddatei mithilfe der PropertyItem -Klasse und der Image.PropertyItems -Eigenschaft gelesen und angezeigt werden.

Dieses Beispiel ist für die Verwendung in einem Windows-Formular konzipiert, das den System.Drawing.Imaging Namespace importiert. Fügen Sie den Code in das Formular ein, und ändern Sie den Pfad in fakePhoto.jpg , um auf eine Bilddatei auf Ihrem System zu verweisen. Rufen Sie die ExtractMetaData -Methode auf, wenn Sie das Ereignis des Formulars Paint behandeln, und übergeben Sie e als 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

Hinweise

Die Daten bestehen aus: einem Bezeichner, der Länge (in Bytes) der Eigenschaft, dem Eigenschaftstyp und einem Zeiger auf den Eigenschaftswert.

A PropertyItem ist nicht für die Verwendung als eigenständiges Objekt vorgesehen. Ein PropertyItem -Objekt soll von Klassen verwendet werden, die von Imageabgeleitet werden. Ein PropertyItem -Objekt wird verwendet, um die Metadaten vorhandener Bilddateien abzurufen und zu ändern, nicht zum Erstellen der Metadaten. Daher verfügt die PropertyItem Klasse nicht über einen definierten Public Konstruktor, und Sie können keine instance eines PropertyItem Objekts erstellen.

Um das Fehlen eines Public Konstruktors zu umgehen, verwenden Sie ein vorhandenes PropertyItem Objekt, anstatt eine neue instance der PropertyItem -Klasse zu erstellen. Weitere Informationen finden Sie unter Image.GetPropertyItem.

Eigenschaften

Id

Ruft die ID der Eigenschaft ab oder legt diese fest.

Len

Ruft die Länge der Value-Eigenschaft in Bytes ab oder legt die Länge fest.

Type

Ruft eine ganze Zahl ab, die den Typ der in der Value-Eigenschaft enthaltenen Daten definiert, oder legt diese ganze Zahl fest.

Value

Ruft den Wert des Eigenschaftenelements ab oder legt diesen fest.

Methoden

Equals(Object)

Bestimmt, ob das angegebene Objekt gleich dem aktuellen Objekt ist.

(Geerbt von Object)
GetHashCode()

Fungiert als Standardhashfunktion.

(Geerbt von Object)
GetType()

Ruft den Type der aktuellen Instanz ab.

(Geerbt von Object)
MemberwiseClone()

Erstellt eine flache Kopie des aktuellen Object.

(Geerbt von Object)
ToString()

Gibt eine Zeichenfolge zurück, die das aktuelle Objekt darstellt.

(Geerbt von Object)

Gilt für:

Weitere Informationen