Image.SetPropertyItem(PropertyItem) 메서드

정의

Image에 속성 항목(메타데이터)을 저장합니다.

public:
 void SetPropertyItem(System::Drawing::Imaging::PropertyItem ^ propitem);
public void SetPropertyItem (System.Drawing.Imaging.PropertyItem propitem);
member this.SetPropertyItem : System.Drawing.Imaging.PropertyItem -> unit
Public Sub SetPropertyItem (propitem As PropertyItem)

매개 변수

propitem
PropertyItem

저장할 PropertyItem입니다.

예외

이 이미지의 이미지 형식이 속성 항목을 지원하지 않는 경우

예제

다음 코드 예제를 사용 GetPropertyItem 하는 방법을 보여 줍니다는 및 SetPropertyItem 메서드. 이 예제는 Windows Forms 함께 사용하도록 설계되었습니다. 이 예제를 실행하려면 폼에 붙여넣고 메서드를 호출 DemonstratePropertyItem 하고 를 로 전달 ePaintEventArgs하여 폼의 Paint 이벤트를 처리합니다.

private:
   void DemonstratePropertyItem( PaintEventArgs^ e )
   {
      // Create two images.
      Image^ image1 = Image::FromFile( "c:\\FakePhoto1.jpg" );
      Image^ image2 = Image::FromFile( "c:\\FakePhoto2.jpg" );

      // Get a PropertyItem from image1.
      PropertyItem^ propItem = image1->GetPropertyItem( 20624 );

      // Change the ID of the PropertyItem.
      propItem->Id = 20625;

      // Set the PropertyItem for image2.
      image2->SetPropertyItem( propItem );

      // Draw the image.
      e->Graphics->DrawImage( image2, 20.0F, 20.0F );
   }
private void DemonstratePropertyItem(PaintEventArgs e)
{

    // Create two images.
    Image image1 = Image.FromFile("c:\\FakePhoto1.jpg");
    Image image2 = Image.FromFile("c:\\FakePhoto2.jpg");

    // Get a PropertyItem from image1.
    PropertyItem propItem = image1.GetPropertyItem(20624);

    // Change the ID of the PropertyItem.
    propItem.Id = 20625;

    // Set the PropertyItem for image2.
    image2.SetPropertyItem(propItem);

    // Draw the image.
    e.Graphics.DrawImage(image2, 20.0F, 20.0F);
}
Private Sub DemonstratePropertyItem(ByVal e As PaintEventArgs)

    ' Create two images.
    Dim image1 As Image = Image.FromFile("c:\FakePhoto1.jpg")
    Dim image2 As Image = Image.FromFile("c:\FakePhoto2.jpg")

    ' Get a PropertyItem from image1.
    Dim propItem As PropertyItem = image1.GetPropertyItem(20624)

    ' Change the ID of the PropertyItem.
    propItem.Id = 20625

    ' Set the PropertyItem for image2.
    image2.SetPropertyItem(propItem)

    ' Draw the image.
    e.Graphics.DrawImage(image2, 20.0F, 20.0F)
End Sub

설명

이미지 형식이 속성 항목을 지원하지 않는 경우 이 메서드는 "속성이 지원되지 않음"이라는 메시지와 함께 throw됩니다 ArgumentException . 이미지 형식이 속성 항목을 지원하지만 설정하려는 특정 속성을 지원하지 않는 경우 이 메서드는 시도를 무시하지만 예외를 throw하지는 않습니다.

클래스에 공용 생성자가 없으므로 속성 항목을 PropertyItem 설정하기 어렵습니다. 이 제한을 해결하는 한 가지 방법은 속성 값을 검색 PropertyItems 하거나 속성 항목이 이미 있는 의 메서드를 Image 호출 GetPropertyItem 하여 를 가져오는 PropertyItem 것입니다. 그런 다음 의 PropertyItem 필드를 설정하고 에 전달할 SetPropertyItem수 있습니다.

적용 대상