Image.SetPropertyItem(PropertyItem) 方法

定義

在這個 Image 中儲存屬性項目 (中繼資料的項目)。

public void SetPropertyItem (System.Drawing.Imaging.PropertyItem propitem);

參數

propitem
PropertyItem

要儲存的 PropertyItem

例外狀況

此影像的影像格式不支援屬性項目。

範例

下列程式代碼範例示範如何使用 GetPropertyItemSetPropertyItem 方法。 此範例的設計目的是要與 Windows Forms 搭配使用。 若要執行此範例,請將它貼到表單中,並藉由呼叫 DemonstratePropertyItem 方法來處理表單Paint的事件,並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);
}

備註

如果影像格式不支援屬性項目,這個方法會 ArgumentException 擲回訊息「不支援屬性」。如果影像格式支援屬性專案,但不支援您嘗試設定的特定屬性,這個方法會忽略嘗試,但不會擲回例外狀況。

因為類別沒有公用建構函式, PropertyItem 所以很難設定屬性專案。 解決這項限制的其中一種方式,就是擷取PropertyItems屬性值或呼叫GetPropertyItem已經具有屬性專案的方法來Image取得 PropertyItem 。 然後您可以設定的欄位, PropertyItem 並將其傳遞至 SetPropertyItem

適用於