Image::GetPropertyItemSize 方法 (gdiplusheaders.h)

Image::GetPropertyItemSize 方法获取此 Image 对象的指定属性项的大小(以字节为单位)。

语法

UINT GetPropertyItemSize(
  [in] PROPID propId
);

parameters

[in] propId

类型: PROPID

标识属性项的整数。

返回值

类型: UINT

此方法返回此 Image 对象的指定属性项的大小(以字节为单位)。

注解

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

示例

以下示例基于 JPEG 文件创建 Image 对象。 该代码调用该 Image 对象的 Image::GetPropertyItemSize 方法以获取属性项的大小,该属性项保存用于捕获图像的相机的规格。 然后,代码调用 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::GetPropertyItem

Image::GetPropertySize

Image::RemovePropertyItem

Image::SetPropertyItem

PropertyItem

读取和写入元数据