레이블이 GDI인 게시물을 표시합니다. 모든 게시물 표시
레이블이 GDI인 게시물을 표시합니다. 모든 게시물 표시

Visual C++ GDIPLUS 사용하여 JPG 로드하기

/////////////////////////////////////////////////////////////////////
// Visual Studio 2005 이상의 버전에선 GDI+ 가 제공된다.
// GDI+ 사용을 위해서
#include <Gdiplus.h>
#include <GdiplusBase.h>
#include <GdiplusColor.h>
#include <GdiplusPen.h>
#include <GdiplusBrush.h>
#include <GdiplusPath.h>
#include <GdiplusGraphics.h>
using namespace Gdiplus;
#pragma comment(lib, "gdiplus.lib")
/////////////////////////////////////////////////////////////////////

// GDI+ 초기화
ULONG_PTR gpToken;
GdiplusStartupInput gpsi;
if (GdiplusStartup(&gpToken, &gpsi, NULL) != Ok)
{
    MessageBox(NULL, "Fail To Initialize GDI+ Library.", "Error", MB_OK);
    return 0;
}

char cp_filename[100];
memset(cp_filename, 0, sizeof(char)*100);
strcat(cp_filename, "ysotman.jpg");

//현재 PC에 설정된 지역으로 사용
setlocale(LC_ALL, "");
WCHAR *wc_filename = new WCHAR[1000];
memset(wc_filename, 0, sizeof(WCHAR)*1000);
int len = strlen(cp_filename);

// multibyte string to widecharacter string
len = mbstowcs(wc_filename, cp_filename, len);

// 이미지 로드
Image Img(wc_filename, 0);
int width = Img.GetWidth();
int height = Img.GetHeight();
if (I.GetLastStatus() != Ok)
{
    return -1;
}
// 로드한 이미지 화면으로 보이기
Graphics G(hdc);
G.DrawImage(&Img, 0, 0);

// GDI+ 해제
GdiplusShutdown(gpToken);