• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipGetPropertyIdList

Started by José Roca, June 23, 2008, 03:44:36 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



The following example creates an Image object based on a JPEG file. The code calls the GdipGetPropertyCount function of that Image object to find out how many properties are stored in the image. Then the code calls the GdipGetPropertyIdList function to get a list of the property types.

C++


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

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

   UINT count = 0;
   Image* image = new Image(L"FakePhoto.jpg");

   // How many types of metadata are in the image?
   count = image->GetPropertyCount();
   if(count == 0)
      return 0;

   // Allocate a buffer to receive an array of PROPIDs.
   PROPID* propIDs = new PROPID[count];

   image->GetPropertyIdList(count, propIDs);

   // List the retrieved IDs.
   for(UINT j = 0; j < count; ++j)
      printf("%x\n", propIDs[j]);

   delete [] propIDs;
   delete image;   
 
   GdiplusShutdown(gdiplusToken);
   return 0;
}


PowerBASIC


#COMPILE EXE
#DIM ALL
#INCLUDE "GDIPLUS.INC"

' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN

   LOCAL hStatus AS LONG
   LOCAL token AS DWORD
   LOCAL StartupInput AS GdiplusStartupInput
   LOCAL pImage AS DWORD
   LOCAL strFileName AS STRING
   LOCAL count AS DWORD
   LOCAL i AS LONG
   DIM   propIDs(0) AS DWORD

   ' // Initialize GDI+
   StartupInput.GdiplusVersion = 1
   hStatus = GdiplusStartup(token, StartupInput, BYVAL %NULL)
   IF hStatus THEN
      PRINT "Error initializing GDI+"
      EXIT FUNCTION
   END IF

   strFileName = UCODE$("Shapes.jpg")
   hStatus = GdipLoadImageFromFile(STRPTR(strFileName), pImage)

   hStatus = GdipGetPropertyCount(pImage, count)
   PRINT "Number of properties =" & STR$(count)

   REDIM propIDs(count - 1)
   hStatus = GdipGetPropertyIdList(pImage, count, propIDs(0))
   FOR i = 0 TO count - 1
      PRINT HEX$(propIDs(i))
   NEXT

   ' // Cleanup
   IF pImage THEN GdipDisposeImage(pImage)

   ' // Shutdown GDI+
   GdiplusShutdown token

   WAITKEY$

END FUNCTION
' ========================================================================================