Export (0) Print
Expand All

Image.GetPropertyItem Method

Gets the specified property item from this Image.

Namespace: System.Drawing
Assembly: System.Drawing (in system.drawing.dll)

public PropertyItem GetPropertyItem (
	int propid
)
public PropertyItem GetPropertyItem (
	int propid
)
public function GetPropertyItem (
	propid : int
) : PropertyItem
Not applicable.

Parameters

propid

The ID of the property item to get.

Return Value

The PropertyItem this method gets.

Exception typeCondition

ArgumentException

The image format of this image does not support property items.

It is difficult to set property items, because the PropertyItem class has no public constructors. One way to work around this restriction is to obtain a PropertyItem by retrieving the PropertyItems property value or calling the GetPropertyItem method of an Image that already has property items. Then you can set the fields of the PropertyItem and pass it to SetPropertyItem.

The following code example demonstrates how to use the GetPropertyItem and SetPropertyItem methods. This example is designed to be used with Windows Forms. To run this example, paste it into a form, and handle the form's Paint event by calling the DemonstratePropertyItem method, passing e as 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.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 Server 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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft