Image.SetPropertyItem(PropertyItem) 方法   
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
在此 Image 中存储一个属性项(元数据片)。
public:
 void SetPropertyItem(System::Drawing::Imaging::PropertyItem ^ propitem);public void SetPropertyItem (System.Drawing.Imaging.PropertyItem propitem);member this.SetPropertyItem : System.Drawing.Imaging.PropertyItem -> unitPublic Sub SetPropertyItem (propitem As PropertyItem)参数
- propitem
- PropertyItem
要存储的 PropertyItem。
例外
此图像的图像格式不支持属性项。
示例
下面的代码示例演示如何使用 GetPropertyItem 和 SetPropertyItem 方法。 此示例旨在与 Windows 窗体 一起使用。 若要运行此示例,请将其粘贴到窗体中,并通过调用 DemonstratePropertyItem 方法处理窗体的事件Paint,并将其ePaintEventArgs作为 传递。
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
注解
如果图像格式不支持属性项,此方法将 ArgumentException 引发消息“不支持属性”。如果图像格式支持属性项,但不支持尝试设置的特定属性,则此方法将忽略该尝试,但不引发异常。
很难设置属性项,因为 PropertyItem 类没有公共构造函数。 解决此限制的一种方法是通过检索PropertyItems属性值或调用GetPropertyItem已具有属性项的 的 Image 方法获取 PropertyItem 。 然后,可以设置 的 PropertyItem 字段并将其传递给 SetPropertyItem。