PropertyItem 类

定义

封装要包括到图像文件中的元数据属性。 不可继承。

C#
public sealed class PropertyItem
继承
PropertyItem

示例

下面的代码示例演示如何使用 PropertyItem 类和 属性读取和显示图像文件中的 Image.PropertyItems 元数据。

此示例设计为在导入 命名空间的 System.Drawing.Imaging Windows 窗体中使用。 将代码粘贴到窗体中,并将路径 fakePhoto.jpg 更改为 以指向系统上的图像文件。 ExtractMetaData在处理窗体的 Paint 事件时调用 方法,作为 ePaintEventArgs传递。

C#
private void ExtractMetaData(PaintEventArgs e)
{
    try
    {
        // Create an Image object. 
        Image theImage = new Bitmap("c:\\fakePhoto.jpg");

        // Get the PropertyItems property from image.
        PropertyItem[] propItems = theImage.PropertyItems;

        // Set up the display.
        Font font1 = new Font("Arial", 10);
        SolidBrush blackBrush = new SolidBrush(Color.Black);
        int X = 0;
        int Y = 0;

        // For each PropertyItem in the array, display the id, 
        // type, and length.
        int count = 0;
        foreach ( PropertyItem propItem in propItems )
        {
            e.Graphics.DrawString("Property Item " + 
                count.ToString(), font1, blackBrush, X, Y);
            Y += font1.Height;

            e.Graphics.DrawString("   ID: 0x" + 
                propItem.Id.ToString("x"), font1, blackBrush, X, Y);
            Y += font1.Height;

            e.Graphics.DrawString("   type: " +
                propItem.Type.ToString(), font1, blackBrush, X, Y);
            Y += font1.Height;

            e.Graphics.DrawString("   length: " + 
                propItem.Len.ToString() + 
                " bytes", font1, blackBrush, X, Y);
            Y += font1.Height;
            count += 1;
        }
        font1.Dispose();
    }
    catch(Exception)
    {
        MessageBox.Show("There was an error." + 
            "Make sure the path to the image file is valid.");
    }
}

注解

数据包括:标识符、属性) 长度 (字节数、属性类型和指向属性值的指针。

PropertyItem不应用作独立对象。 对象 PropertyItem 旨在由派生自 Image的类使用。 对象 PropertyItem 用于检索和更改现有图像文件的元数据,而不是创建元数据。 因此, PropertyItem 类没有定义的 Public 构造函数,并且无法创建 对象的实例 PropertyItem

若要解决缺少构造函数的情况 Public ,请使用现有 PropertyItem 对象,而不是创建 类的新实例 PropertyItem 。 有关详细信息,请参阅 Image.GetPropertyItem

属性

Id

获取或设置属性的 ID。

Len

获取或设置 Value 属性的长度(以字节为单位)。

Type

获取或设置整数,它定义 Value 属性包含的数据类型。

Value

获取或设置属性项的值。

方法

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

适用于

产品 版本
.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

另请参阅