Image::SetPropertyItem 方法 (gdiplusheaders.h)

Image::SetPropertyItem 方法會為此 Image 物件設定屬性專案 (一段元數據) 。 如果專案已經存在,則會更新其內容;否則,會新增專案。

語法

Status SetPropertyItem(
  [in] const PropertyItem *item
);

參數

[in] item

類型: const PropertyItem*

PropertyItem 物件的指標,指定要設定的屬性專案。

傳回值

類型: 狀態

如果方法成功,它會傳回Ok,這是 Status 列舉的元素。

如果方法失敗,它會傳回 Status 列舉的其中一個其他元素。

備註

某些影像格式 (例如,ICON 和 EMF) 不支援屬性。 如果您在不支援屬性的映射上呼叫 Image::SetPropertyItem 方法,則會傳回 PropertyNotSupported。

範例

下列主控台應用程式會根據 JPEG 檔案建立 Image 物件。 程序代碼會呼叫該 Image 物件的 Image::SetPropertyItem 方法,以設定影像的標題。 然後程式代碼會擷取並顯示新的標題。

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

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

   // Create an Image object based on a JPEG file.
   Image* image = new Image(L"FakePhoto.jpg");

   // Set the image title.
   PropertyItem* propItem = new PropertyItem;
   CHAR newTitleValue[] = "Fake Photograph 2";

   propItem->id = PropertyTagImageTitle;
   propItem->length = 18;  //  includes null terminator
   propItem->type = PropertyTagTypeASCII;
   propItem->value = newTitleValue;

   image->SetPropertyItem(propItem);

   // Get and display the new image title.
   UINT size = image->GetPropertyItemSize(PropertyTagImageTitle);
   PropertyItem* title = (PropertyItem*)malloc(size);
   image->GetPropertyItem(PropertyTagImageTitle, size, title);
   printf("The image title is %s.\n", title->value);

   free(title);
   delete propItem;
   delete image;
   GdiplusShutdown(gdiplusToken);
   return 0;
}

規格需求

需求
最低支援的用戶端 Windows XP、Windows 2000 Professional [僅限傳統型應用程式]
最低支援的伺服器 Windows 2000 Server [僅限傳統型應用程式]
目標平台 Windows
標頭 gdiplusheaders.h (包含 Gdiplus.h)
程式庫 Gdiplus.lib
Dll Gdiplus.dll

另請參閱

映像

Image::GetPropertyCount

Image::GetPropertyIdList

Image::GetPropertyItem

Image::GetPropertyItemSize

Image::GetPropertySize

Image::RemovePropertyItem

PropertyItem

讀取和寫入元數據