Aracılığıyla paylaş


PropertyItem Sınıf

Tanım

Görüntü dosyasına eklenecek meta veri özelliğini kapsüller. Devralınamaz.

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

Örnekler

Aşağıdaki kod örneği, sınıfını ve özelliğini kullanarak PropertyItem bir görüntü dosyasında meta verilerin nasıl okunup görüntüleneceğini Image.PropertyItems gösterir.

Bu örnek, ad alanını içeri aktaran System.Drawing.Imaging bir Windows Formunda kullanılacak şekilde tasarlanmıştır. Kodu forma yapıştırın ve yolu fakePhoto.jpg sisteminizdeki bir görüntü dosyasını işaret etmek üzere değiştirin. Formun ExtractMetaDataPaint olayını işlerken yöntemini çağırın e ve olarak geçirin 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

Açıklamalar

Veriler şunlardan oluşur: tanımlayıcı, özelliğin uzunluğu (bayt cinsinden), özellik türü ve özellik değerine yönelik bir işaretçi.

A PropertyItem , tek başına nesne olarak kullanılmak üzere tasarlanmamıştır. Nesnesi PropertyItem , öğesinden Imagetüretilen sınıflar tarafından kullanılmak üzere tasarlanmıştır. Nesne PropertyItem , meta verileri oluşturmak için değil, var olan görüntü dosyalarının meta verilerini almak ve değiştirmek için kullanılır. Bu nedenle, sınıfı tanımlı PropertyItemPublic bir oluşturucuya sahip değildir ve bir PropertyItem nesnenin örneğini oluşturamazsınız.

Oluşturucunun yokluğuna geçici bir Public çözüm bulmak için, sınıfın yeni bir örneğini PropertyItem oluşturmak yerine var olan PropertyItem bir nesneyi kullanın. Daha fazla bilgi için bkz. Image.GetPropertyItem.

Özellikler

Name Description
Id

Özelliğin kimliğini alır veya ayarlar.

Len

Özelliğin uzunluğunu (bayt cinsinden) Value alır veya ayarlar.

Type

özelliğinde Value yer alan veri türünü tanımlayan bir tamsayı alır veya ayarlar.

Value

Özellik öğesinin değerini alır veya ayarlar.

Yöntemler

Name Description
Equals(Object)

Belirtilen nesnenin geçerli nesneye eşit olup olmadığını belirler.

(Devralındığı yer: Object)
GetHashCode()

Varsayılan karma işlevi işlevi görür.

(Devralındığı yer: Object)
GetType()

Geçerli örneğin Type alır.

(Devralındığı yer: Object)
MemberwiseClone()

Geçerli Objectbasit bir kopyasını oluşturur.

(Devralındığı yer: Object)
ToString()

Geçerli nesneyi temsil eden bir dize döndürür.

(Devralındığı yer: Object)

Şunlara uygulanır

Ayrıca bkz.