카테고리 없음
GDI+ 를 사용하여 이미지 출력하기
코드베어
2020. 6. 1. 21:58
GDI+를 사용하여 편리하게 이미지를 출력할 수 있다.
WM_PAINT 호출 함수( OnPaint )에서 사용 예제이다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
CPaintDC dc( m_hWnd );
CDC mDC;
CBitmap mBitmap;
CBitmap mBitmap_old;
CRect rect;
GetClientRect(&rect);
// 메모리 DC, 비트맵 생성 ( 더블 버퍼링 )
mDC.CreateCompatibleDC( dc );
mBitmap.CreateCompatibleBitmap(dc, rect.right, rect.bottom);
mBitmap_old = mDC.SelectBitmap(mBitmap);
// 메모리 DC에 이미지 출력
Gdiplus::Graphics gr( mDC );
GdiPlus::Image* pImg = ::new Gdiplus::Image(L"image.png");
gr.DrawImage( pImg, Gdiplus::Rect(0, 0, pImg->GetWidth(), pImg->GetHeight(), Gdiplus::Unit::UnitPixel );
dc.Bitblt( 0, 0, rect.Width(), rect.Height(), mDC, 0, 0, SRCCOPY );
// 메모리 DC, 비트맵 해제
mDC.SelectBitmap( mBitmap_old );
mDC.DeleteDC();
mBitmap.DeleteObject();
|
Gdiplus::Image 객체를 이용하여 이미지 파일을 불러오고 Graphics 객체를 이용하여 메모리 DC에 불러온 이미지를 출력한다.