The following console application creates an Image object based on a TIFF file. The code calls the
GdipImageGetFrameDimensionsCount function to find out how many frame dimensions the Image object has. Each of those frame dimensions is identified by a GUID, and the call to
GdipImageGetFrameDimensionsList retrieves those GUIDs. The first GUID is at index 0 in the
dimensionIDs array. The call to the
GdipImageGetFrameCount function determines the number of frames in the dimension identified by the first GUID.
C++
#include <windows.h>
#include <gdiplus.h>
#include <stdio.h>
using namespace Gdiplus;
INT main()
{
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
Image* image = new Image(L"Multiframe.tif");
// How many frame dimensions does the Image object have?
UINT count = 0;
count = image->GetFrameDimensionsCount();
printf("The number of dimensions is %d.\n", count);
GUID* pDimensionIDs = (GUID*)malloc(sizeof(GUID)*count);
// Get the list of frame dimensions from the Image object.
image->GetFrameDimensionsList(pDimensionIDs, count);
// Display the GUID of the first (and only) frame dimension.
WCHAR strGuid[39];
StringFromGUID2(pDimensionIDs[0], strGuid, 39);
wprintf(L"The first (and only) dimension ID is %s.\n", strGuid);
// Get the number of frames in the first dimension.
UINT frameCount = image->GetFrameCount(&pDimensionIDs[0]);
printf("The number of frames in that dimension is %d.\n", frameCount);
free(pDimensionIDs);
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 frameCount AS DWORD
DIM dimensionIDs(0) AS GUID
' // Initialize GDI+
StartupInput.GdiplusVersion = 1
hStatus = GdiplusStartup(token, StartupInput, BYVAL %NULL)
IF hStatus THEN
PRINT "Error initializing GDI+"
EXIT FUNCTION
END IF
strFileName = UCODE$("Multiframe.tif")
hStatus = GdipLoadImageFromFile(STRPTR(strFileName), pImage)
' // How many frame dimensions does the Image object have?
hStatus = GdipImageGetFrameDimensionsCount(pImage, count)
PRINT "The number of dimensions is" & STR$(count)
IF count THEN
' // Get the list of frame dimensions from the Image object.
IF count > 0 THEN REDIM dimensionIDs(count - 1)
hStatus = GdipImageGetFrameDimensionsList(pImage, dimensionIDs(0), count)
' // Display the GUID of the first (and only) frame dimension.
PRINT "The first (and only) dimension ID is " & GUIDTXT$(dimensionIDs(0))
' // Get the number of frames in the first dimension.
hStatus = GdipImageGetFrameCount(pImage, dimensionIDs(0), frameCount)
PRINT "The number of frames in that dimension is" & STR$(frameCount)
END IF
' // Cleanup
IF pImage THEN GdipDisposeImage(pImage)
' // Shutdown GDI+
GdiplusShutdown token
WAITKEY$
END FUNCTION
' ========================================================================================