语言

Image.GetPropertyItem(Int32) 方法

定义

从此 Image获取指定的属性项。

public:
 System::Drawing::Imaging::PropertyItem ^ GetPropertyItem(int propid);
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。

返回

此方法 PropertyItem 获取。

例外

此图像的图像格式不支持属性项。

示例

下面的代码示例演示如何使用 GetPropertyItem 和 SetPropertyItem 方法。 此示例调用 GetPropertyItem 传递 ID 值。 有关 ID 值的列表, Id请参阅。此示例旨在与 Windows 窗体一起使用。 若要运行此示例,请将其粘贴到窗体中,并通过调用Paint该方法(作为传递DemonstratePropertyItem方式e)处理表单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 的列表和指向详细信息的链接,请参阅 Id。

很难设置属性项,因为 PropertyItem 类没有公共构造函数。 解决此限制的一种方法是通过检索PropertyItem属性值或调用PropertyItems已具有属性项的方法来获取GetPropertyItem该限制Image。 然后,可以设置 PropertyItem 字段并将其传递给 SetPropertyItem。

适用于