Image.GetPropertyItem(Int32) 方法

定义

从该 Image 获取指定的属性项。Gets the specified property item from this Image.

public:
 System::Drawing::Imaging::PropertyItem ^ GetPropertyItem(int propid);
public System.Drawing.Imaging.PropertyItem GetPropertyItem (int propid);
member this.GetPropertyItem : int -> System.Drawing.Imaging.PropertyItem
Public Function GetPropertyItem (propid As Integer) As PropertyItem

参数

propid
Int32

要获取的属性项的 ID。The ID of the property item to get.

返回

此方法获取的 PropertyItemThe PropertyItem this method gets.

异常

此图像的图像格式不支持属性项。The image format of this image does not support property items.

示例

下面的代码示例演示如何使用 GetPropertyItemSetPropertyItem 方法。The following code example demonstrates how to use the GetPropertyItem and SetPropertyItem methods. 此示例调用 GetPropertyItem 传递 ID 值。This example calls GetPropertyItem passing an ID value. 有关 ID 值的列表,请参阅 IdFor a list of ID values see, Id. 此示例旨在与 Windows 窗体一起使用。This example is designed to be used with Windows Forms. 若要运行此示例,请将其粘贴到窗体中,并通过调用 DemonstratePropertyItem 方法来处理窗体的 Paint 事件,并将 e 作为 PaintEventArgs传递。To run this example, paste it into a form, and handle the form's Paint event by calling the DemonstratePropertyItem method, passing e as PaintEventArgs.

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

注解

有关属性项 Id 列表和指向详细信息的链接,请参阅 IdFor a list of property item IDs and links to more information, see Id.

由于 PropertyItem 类没有公共构造函数,因此很难设置属性项。It is difficult to set property items, because the PropertyItem class has no public constructors. 解决此限制的一种方法是通过检索 PropertyItems 属性值或调用已有属性项的 ImageGetPropertyItem 方法来获取 PropertyItemOne way to work around this restriction is to obtain a PropertyItem by retrieving the PropertyItems property value or calling the GetPropertyItem method of an Image that already has property items. 然后,可以设置 PropertyItem 的字段并将其传递给 SetPropertyItemThen you can set the fields of the PropertyItem and pass it to SetPropertyItem.

适用于