在基于单文档的MFC下怎样显示BMP图片

来源:百度知道 编辑:UC知道 时间:2024/09/24 02:41:25
已经把原始数据转换为256色的BMP格式的图像 返回的是储存BMP图象信息及位数据的内存块句柄 现在如何通过这个句柄用OnDraw显示图像?

// This OnDraw() handler loads a bitmap from system resources,
// centers it in the view, and uses BitBlt() to paint the bitmap
// bits.

void CBlat2View::OnDraw(CDC* pDC)
{
CBlat2Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);

// load IDB_BITMAP1 from our resources
CBitmap bmp;
if (bmp.LoadBitmap(IDB_BITMAP1))
{
// Get the size of the bitmap
BITMAP bmpInfo;
bmp.GetBitmap(&bmpInfo);

// Create an in-memory DC compatible with the
// display DC we're using to paint
CDC dcMemory;
dcMemory.CreateCompatibleDC(pDC);

// Select the bitmap into the in-memory DC
CBitmap* pOldBitmap = dcMemory.SelectObject(&bmp);

// Find a centerpoint for the bitmap in the client area
CRect rect;
GetClientRect(&rect);
int nX = rect.left + (rect.Width() - bmpInfo.bmWidth) /