Image.GetPropertyItem 方法

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

**命名空间:**System.Drawing
**程序集:**System.Drawing(在 system.drawing.dll 中)

语法

声明
Public Function GetPropertyItem ( _
    propid As Integer _
) As PropertyItem
用法
Dim instance As Image
Dim propid As Integer
Dim returnValue As PropertyItem

returnValue = instance.GetPropertyItem(propid)
public PropertyItem GetPropertyItem (
    int propid
)
public:
PropertyItem^ GetPropertyItem (
    int propid
)
public PropertyItem GetPropertyItem (
    int propid
)
public function GetPropertyItem (
    propid : int
) : PropertyItem

参数

  • propid
    要获取的属性项的 ID。

返回值

此方法获取的 PropertyItem

异常

异常类型 条件

ArgumentException

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

备注

因为 PropertyItem 类没有公共构造函数,所以很难设置属性项。一种可以摆脱此限制的方法是设法获得 PropertyItem,具体方法是通过检索 PropertyItems 属性值,或者通过调用一个已经具有属性项的 ImageGetPropertyItem 方法。然后就可以设置 PropertyItem 的字段,并将其传递给 SetPropertyItem

示例

下面的代码示例演示如何使用 GetPropertyItemSetPropertyItem 方法。此示例是针对使用 Windows 窗体而设计的。若要运行此示例,请将其粘贴到一个窗体中,然后通过调用 DemonstratePropertyItem 方法处理该窗体的 Paint 事件,并将 e 作为 PaintEventArgs 传递。

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
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 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.set_Id(20625);

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

    // Draw the image.
    e.get_Graphics().DrawImage(image2, 20, 20);
} //DemonstratePropertyItem

平台

Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

Image 类
Image 成员
System.Drawing 命名空间