PropertyItem 클래스

정의

메타데이터 속성을 캡슐화하여 이미지 파일에 포함시킵니다. 상속할 수 없습니다.

public ref class PropertyItem sealed
public sealed class PropertyItem
type PropertyItem = class
Public NotInheritable Class PropertyItem
상속
PropertyItem

예제

다음 코드 예제에서는 읽고 클래스 및 속성을 사용 하 여 이미지 파일에서 메타데이터를 표시 하는 PropertyItemImage.PropertyItems 방법을 보여 줍니다.

이 예제는 네임스페이스를 System.Drawing.Imaging 가져오는 Windows Form에서 사용하도록 설계되었습니다. 코드를 양식에 붙여넣고 시스템의 이미지 파일을 가리키도록 경로를 fakePhoto.jpg 로 변경합니다. ExtractMetaData 로 전달 ePaintEventArgs하여 폼의 Paint 이벤트를 처리할 때 메서드를 호출합니다.

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

설명

데이터는 식별자, 속성의 길이(바이트), 속성 형식 및 속성 값에 대한 포인터로 구성됩니다.

PropertyItem 은 독립 실행형 개체로 사용할 수 없습니다. PropertyItem 개체는 에서 파생된 클래스에서 Image사용됩니다. PropertyItem 개체는 메타데이터를 만들지 않고 기존 이미지 파일의 메타데이터를 검색하고 변경하는 데 사용됩니다. 따라서 클래스에 PropertyItem 정의된 Public 생성자가 없으며 개체의 PropertyItem instance 만들 수 없습니다.

생성자의 부재를 Public 해결하려면 클래스의 새 instance 만드는 대신 기존 PropertyItem 개체를 PropertyItem 사용합니다. 자세한 내용은 Image.GetPropertyItem를 참조하세요.

속성

Id

속성의 ID를 가져오거나 설정합니다.

Len

Value 속성의 길이(바이트)를 가져오거나 설정합니다.

Type

Value 속성에 포함된 데이터의 형식을 정의하는 정수를 가져오거나 설정합니다.

Value

속성 항목의 값을 가져오거나 설정합니다.

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상

추가 정보