BMP 이미지를 PNG 이미지로 변환

이미지를 디스크 파일에 저장하려면 Image 클래스의 Save 메서드를 호출합니다. 다음 콘솔 애플리케이션은 디스크 파일에서 BMP 이미지를 로드하고, 이미지를 PNG 형식으로 변환하고, 변환된 이미지를 새 디스크 파일에 저장합니다. 기본 함수는 인코더에 대한 클래스 식별자 검색에 표시된 도우미 함수 GetEncoderClsid를 사용합니다.

#include <windows.h>
#include <gdiplus.h>
#include <stdio.h>
using namespace Gdiplus;

INT GetEncoderClsid(const WCHAR* format, CLSID* pClsid);  // helper function

INT main()
{
   // Initialize GDI+.
   GdiplusStartupInput gdiplusStartupInput;
   ULONG_PTR gdiplusToken;
   GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

   CLSID   encoderClsid;
   Status  stat;
   Image*   image = new Image(L"Bird.bmp");

   // Get the CLSID of the PNG encoder.
   GetEncoderClsid(L"image/png", &encoderClsid);

   stat = image->Save(L"Bird.png", &encoderClsid, NULL);

   if(stat == Ok)
      printf("Bird.png was saved successfully\n");
   else
      printf("Failure: stat = %d\n", stat); 

   delete image;
   GdiplusShutdown(gdiplusToken);
   return 0;
}