Share via


インストールされているエンコーダーの一覧表示

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