The following example creates an Image object based on a JPEG file. The code gets the luminance table by passing the
PropertyTagLuminanceTable constant to the
GdipGetPropertyItem function.
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 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;
}
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 nSize AS DWORD
LOCAL buffer AS STRING
LOCAL propItem AS PropertyItem
LOCAL i AS LONG
LOCAL pvShort AS INTEGER PTR
' // Initialize GDI+
StartupInput.GdiplusVersion = 1
hStatus = GdiplusStartup(token, StartupInput, BYVAL %NULL)
IF hStatus THEN
PRINT "Error initializing GDI+"
EXIT FUNCTION
END IF
strFileName = UCODE$("climber.jpg")
hStatus = GdipLoadImageFromFile(STRPTR(strFileName), pImage)
' // Get the size of that property item.
hStatus = GdipGetPropertyItemSize(pImage, %PropertyTagLuminanceTable, nSize)
' // Use an string as the buffer.
buffer = SPACE$(nSize)
hStatus = GdipGetPropertyItem(pImage, %PropertyTagLuminanceTable, nSize, BYVAL STRPTR(buffer))
IF hStatus = %StatusOk THEN
LSET propItem = LEFT$(buffer, SIZEOF(PropertyItem))
pvShort = propItem.value
FOR i = 1 TO propItem.length \ 2 ' Divide the length by the size of an integer
PRINT @pvShort[i-1] " ";
NEXT
END IF
' // Cleanup
IF pImage THEN GdipDisposeImage(pImage)
' // Shutdown GDI+
GdiplusShutdown token
WAITKEY$
END FUNCTION
' ========================================================================================