Image::GetPropertyItem 方法 (gdiplusheaders.h)

Image::GetPropertyItem 方法从此 Image 对象获取指定的属性项 (一段元数据) 。

语法

Status GetPropertyItem(
  [in]  PROPID       propId,
  [in]  UINT         propSize,
  [out] PropertyItem *buffer
);

参数

[in] propId

类型: PROPID

标识要检索的属性项的整数。

[in] propSize

类型: UINT

指定要检索的属性项的大小(以字节为单位)的整数。 调用 Image::GetPropertyItemSize 方法以确定大小。

[out] buffer

类型: PropertyItem*

指向接收属性项的 PropertyItem 对象的指针。

返回值

类型: 状态

如果该方法成功,则返回 Ok,这是 Status 枚举的元素。

如果方法失败,它将返回 Status 枚举的其他元素之一。

注解

Image::GetPropertyItem 方法返回 PropertyItem 对象。 在调用 Image::GetPropertyItem 之前,必须分配一个足够大的缓冲区来接收该对象 - 大小因数据类型和属性项的值而异。 可以调用 Image 对象的 Image::GetPropertyItemSize 方法来获取所需缓冲区的大小(以字节为单位)。

示例

以下示例基于 JPEG 文件创建 Image 对象。 该代码通过将 PropertyTagEquipMake 常量传递给 Image 对象的 Image::GetPropertyItem 方法,获取捕获 图像 的相机的生成。

#include <windows.h>
#include <gdiplus.h>
#include <stdio.h>
using namespace Gdiplus;

INT main()
{
   GdiplusStartupInput gdiplusStartupInput;
   ULONG_PTR gdiplusToken;
   GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

   UINT size = 0;
   PropertyItem* propertyItem = NULL;
   Image* image = new Image(L"FakePhoto.jpg");

   // Assume that the image has a property item of type PropertyItemEquipMake.
   // Get the size of that property item.
   size = image->GetPropertyItemSize(PropertyTagEquipMake);

   // Allocate a buffer to receive the property item.
   propertyItem = (PropertyItem*)malloc(size);

   // Get the property item.
   image->GetPropertyItem(PropertyTagEquipMake, size, propertyItem);

   // Display the members of the retrieved PropertyItem object.
   printf("The length of the property item is %u.\n", propertyItem->length);
   printf("The data type of the property item is %u.\n", propertyItem->type);

   if(propertyItem->type == PropertyTagTypeASCII)
      printf("The value of the property item is %s.\n", propertyItem->value);

   free(propertyItem);
   delete image;
   GdiplusShutdown(gdiplusToken);
   return 0;
}

前面的代码以及特定文件 FakePhoto.jpg 生成了以下输出。 请注意,数据类型为 2,即 Gdiplusimaging.h 中定义的 PropertyTagTypeASCII 常量的值。

The length of the property item is 17.
The data type of the property item is 2.
The value of the property item is Northwind Traders.

要求

要求
最低受支持的客户端 Windows XP、Windows 2000 Professional [仅限桌面应用]
最低受支持的服务器 Windows 2000 Server [仅限桌面应用]
目标平台 Windows
标头 gdiplusheaders.h (包括 Gdiplus.h)
Library Gdiplus.lib
DLL Gdiplus.dll

另请参阅

图像

Image::GetAllPropertyItems

Image::GetPropertyCount

Image::GetPropertyIdList

Image::GetPropertyItemSize

Image::GetPropertySize

Image::RemovePropertyItem

Image::SetPropertyItem

PropertyItem

读取和写入元数据