C언어
2022 gdipluse 사용법, png 파일 이미지 로딩
바람사탕
2022. 8. 27. 23:59
반응형
#include <objidl.h>
#include <gdiplus.h>
using namespace Gdiplus;
#pragma comment (lib,"Gdiplus.lib")
void strcpy(wchar_t* buf, const char* s)
{
int nLen = MultiByteToWideChar(CP_ACP,
0,
s, -1,
NULL,
NULL);
MultiByteToWideChar(CP_ACP,
0,
s, -1,
buf,
nLen);
}
HBITMAP LoadPng(const char* file1,int *w,int *h)
{
wchar_t file[1024];
strcpy(file, file1);
HBITMAP hb = 0;
int bok = 0;
Image image(file);
*w = image.GetWidth();
if (*w > 0)
{
*h = image.GetHeight();
if (*h > 0)
{
HDC hdc = GetDC(0);
if (hdc)
{
HDC hdc_mem = ::CreateCompatibleDC(hdc);
hb = ::CreateCompatibleBitmap(hdc, *w, *h);
ReleaseDC(0, hdc);
::SelectObject(hdc_mem, hb);
Graphics graphics(hdc_mem);
graphics.DrawImage(&image, 0, 0);
::DeleteDC(hdc_mem);
bok = 1;
}
}
}
if (bok == 0)
{
*w = 0;
*h = 0;
}
return hb;
}
void BitBlt(HDC hdc, int x, int y, int cx,int cy, HBITMAP hb, int x1, int y1,DWORD op)
{
HDC hdc_mem= CreateCompatibleDC(hdc);
::SelectObject(hdc_mem, hb);
BitBlt(hdc, x, y, cx, cy, hdc_mem, x1, y1, op);
::DeleteDC(hdc_mem);
}
HBITMAP hb_back_img;
int hb_back_img_w, hb_back_img_h;
hb_back_img=LoadPng("C:\\601-1.png",&hb_back_img_w,&hb_back_img_h);
반응형