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)
程式庫 Gdiplus.lib
Dll Gdiplus.dll

另請參閱

映像

Image::GetAllPropertyItems

Image::GetPropertyCount

Image::GetPropertyIdList

Image::GetPropertyItemSize

Image::GetPropertySize

Image::RemovePropertyItem

Image::SetPropertyItem

PropertyItem

讀取和寫入元數據