标签 GDI+ 下的文章

GDI+ DrawImage Example

GDI+ DrawImage Example

stdafx.h加上:

#include <windows.h>
#include <gdiplus.h>
#pragma comment(lib, "gdiplus.lib")
using namespace Gdiplus;

CXXApp中加入变量

ULONG_PTR m_gdiplusToken;

InitInstance()中加入

Gdiplus::GdiplusStartupInput StartupInput;  
GdiplusStartup(&m_gdiplusToken,&StartupInput,NULL);  

ExitInstance中加入

Gdiplus::GdiplusShutdown(m_gdiplusToken);

CXXDlg::OnPaint()中加入:

CPaintDC dc(this); 
HDC m_memDC = ::CreateCompatibleDC(dc.m_hDC);
Image* img = new Image( L"D:\dev6\rit8.0\output\skin\default\Backup.png" );
HBITMAP m_bmp = ::CreateCompatibleBitmap(dc.m_hDC, img->GetWidth(), img->GetHeight());
SelectObject(m_memDC,m_bmp);
Graphics* graph = new Graphics(m_memDC);
graph->DrawImage(img, 0, 0, img->GetWidth(), img->GetHeight());
BitBlt(dc.m_hDC,0,0,img->GetWidth(),img->GetHeight(),m_memDC,0,0,SRCCOPY);