The following console application uses the GdipGetImageEncoders function to get an array of ImageCodecInfo structures that contain information about the available image encoders.
C++
#include <windows.h>
#include <gdiplus.h>
#include <stdio.h>
using namespace Gdiplus;
INT main()
{
// Initialize GDI+.
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
UINT num; // number of image encoders
UINT size; // size, in bytes, of the image encoder array
ImageCodecInfo* pImageCodecInfo;
// How many encoders are there?
// How big (in bytes) is the array of all ImageCodecInfo obects?
GetImageEncodersSize(&num, &size);
// Create a buffer large enough to hold the array of ImageCodecInfo
// objects that will be returned by GetImageEncoders.
pImageCodecInfo = (ImageCodecInfo*)(malloc(size));
// GetImageEncoders creates an array of ImageCodecInfo objects
// and copies that array into a previously allocated buffer.
// The third argument, imageCodecInfos, is a pointer to that buffer.
GetImageEncoders(num, size, pImageCodecInfo);
// Display the graphics file format (MimeType)
// for each ImageCodecInfo object.
for(UINT j = 0; j < num; ++j)
{
wprintf(L"%s\n", pImageCodecInfo[j].MimeType);
}
free(pImageCodecInfo);
GdiplusShutdown(gdiplusToken);
return 0;
}
PowerBASIC
#COMPILE EXE
#DIM ALL
#INCLUDE "GDIPLUS.INC"
#INCLUDE "OLE2UTILS.INC"
' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN
LOCAL hr AS LONG
LOCAL token AS DWORD
LOCAL StartupInput AS GdiplusStartupInput
LOCAL numEncoders AS DWORD
LOCAL nSize AS DWORD
LOCAL i AS LONG
LOCAL x AS LONG
LOCAL p AS BYTE PTR
LOCAL s AS STRING
LOCAL nSigCount AS LONG
LOCAL nSigSize AS LONG
DIM pImageCodecInfo AS ImageCodecInfo PTR
StartupInput.GdiplusVersion = 1
hr = GdiplusStartup(token, StartupInput, BYVAL %NULL)
IF hr THEN
PRINT "Error initializing GDI+"
EXIT FUNCTION
END IF
hr = GdipGetImageEncodersSize(numEncoders, nSize)
PRINT "Number of encoders: " numEncoders
PRINT "Size: " nSize
' Allocate a buffer large enough to hold the array returned by GdpiGetImageEncoders
REDIM buffer(nSize - 1) AS BYTE
pImageCodecInfo = VARPTR(buffer(0))
hr = GdipGetImageEncoders(numEncoders, nSize, BYVAL pImageCodecInfo)
IF hr = 0 THEN
FOR i = 1 TO numEncoders
PRINT "Codec identifier: " GUIDTXT$(@pImageCodecInfo.Clsid)
PRINT "Format identifier: " GUIDTXT$(@pImageCodecInfo.FormatID)
PRINT "Codec name: " W2A_(@pImageCodecInfo.CodecName)
PRINT "Dll name: " W2A_(@pImageCodecInfo.DllName)
PRINT "Format description: " W2A_(@pImageCodecInfo.FormatDescription)
PRINT "Filename extension: " W2A_(@pImageCodecInfo.FileNameExtension)
PRINT "Mime type: " W2A_(@pImageCodecInfo.MimeType)
PRINT "Flags: " @pImageCodecInfo.Flags
PRINT "Version: " @pImageCodecInfo.Version
nSigCount = @pImageCodecInfo.SigCount
PRINT "Signature count: " nSigCount
nSigSize = @pImageCodecInfo.SigSize
PRINT "Signature size: " nSigSize
p = @pImageCodecInfo.SigPattern
s = ""
FOR x = 1 TO nSigCount * nSigSize
s = s + HEX$(@p) + " "
INCR p
NEXT
PRINT "Signature pattern: " s
p = @pImageCodecInfo.SigMask
s = ""
FOR x = 1 TO nSigCount * nSigSize
s = s + HEX$(@p) + " "
INCR p
NEXT
PRINT "Signature mask: " s
INCR pImageCodecInfo '// Increments pointer
PRINT "Press any key"
WAITKEY$
CLS
NEXT
END IF
GdiplusShutdown token
END FUNCTION
' ========================================================================================