列出已安裝的編碼器
GDI+ 提供 GetImageEncoders 函 式,讓您可以判斷電腦上可用的影像編碼器。 GetImageEncoders 會傳回 ImageCodecInfo 物件的陣列。 呼叫 GetImageEncoders之前,您必須配置足以接收該陣列的緩衝區。 您可以呼叫 GetImageEncodersSize 來判斷所需緩衝區的大小。
下列主控台應用程式會列出可用的影像編碼器:
#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 objects?
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, imageCodecInfo, 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;
}
當您執行上述主控台應用程式時,輸出會類似下列內容:
image/bmp
image/jpeg
image/gif
image/tiff
image/png