Image.GetPropertyItem(Int32) 方法

定義

從這個 Image 取得指定的屬性項目。

public System.Drawing.Imaging.PropertyItem GetPropertyItem (int propid);
public System.Drawing.Imaging.PropertyItem? GetPropertyItem (int propid);

參數

propid
Int32

要取得的屬性項目 ID。

傳回

這個方法所取得的 PropertyItem

例外狀況

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

範例

下列程式代碼範例示範如何使用 GetPropertyItemSetPropertyItem 方法。 此範例會呼叫 GetPropertyItem 傳遞標識碼值。 如需識別碼值的清單,Id請參閱 。此範例的設計目的是要與 Windows Forms 搭配使用。 若要執行此範例,請將它貼到表單中,並藉由呼叫 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);
}

備註

如需屬性項目識別碼的清單和詳細資訊的連結,請參閱 Id

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

適用於

產品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9