PropertyItem Clase

Definición

Encapsula una propiedad de metadatos que debe incluirse en un archivo de imagen. No puede heredarse.

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

Ejemplos

En el ejemplo de código siguiente se muestra cómo leer y mostrar los metadatos en un archivo de imagen mediante la PropertyItem clase y la Image.PropertyItems propiedad .

Este ejemplo está diseñado para usarse en un formulario Windows Forms que importa el System.Drawing.Imaging espacio de nombres. Pegue el código en el formulario y cambie la ruta de acceso para fakePhoto.jpg que apunte a un archivo de imagen en el sistema. Llame al ExtractMetaData método al controlar el evento del Paint formulario, pasando e como 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

Comentarios

Los datos constan de: un identificador, la longitud (en bytes) de la propiedad, el tipo de propiedad y un puntero al valor de propiedad.

No PropertyItem está diseñado para usarse como un objeto independiente. Un PropertyItem objeto está diseñado para que lo usen las clases derivadas de Image. Se usa un PropertyItem objeto para recuperar y cambiar los metadatos de los archivos de imagen existentes, no para crear los metadatos. Por lo tanto, la PropertyItem clase no tiene un constructor definido Public y no se puede crear una instancia de un PropertyItem objeto .

Para evitar la ausencia de un Public constructor, use un objeto existente PropertyItem en lugar de crear una nueva instancia de la PropertyItem clase . Para obtener más información, vea Image.GetPropertyItem.

Propiedades

Id

Obtiene o establece el identificador de la propiedad.

Len

Obtiene o establece la longitud, en bytes, de la propiedad Value.

Type

Obtiene o establece un entero que define el tipo de datos contenidos en la propiedad Value.

Value

Obtiene o establece el valor del elemento de la propiedad.

Métodos

Equals(Object)

Determina si el objeto especificado es igual que el objeto actual.

(Heredado de Object)
GetHashCode()

Sirve como la función hash predeterminada.

(Heredado de Object)
GetType()

Obtiene el Type de la instancia actual.

(Heredado de Object)
MemberwiseClone()

Crea una copia superficial del Object actual.

(Heredado de Object)
ToString()

Devuelve una cadena que representa el objeto actual.

(Heredado de Object)

Se aplica a

Consulte también