中易网

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

答案:1  悬赏:0  
解决时间 2021-01-26 04:47
在基于单文档的MFC下怎样显示BMP图片
最佳答案
// 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) / 2;
int nY = rect.top + (rect.Height() - bmpInfo.bmHeight) / 2;

// Copy the bits from the in-memory DC into the on-
// screen DC to actually do the painting. Use the centerpoint
// we computed for the target offset.
pDC->BitBlt(nX, nY, bmpInfo.bmWidth, bmpInfo.bmHeight, &dcMemory,
0, 0, SRCCOPY);

dcMemory.SelectObject(pOldBitmap);
}
else
TRACE0("ERROR: Where's IDB_BITMAP1?\n");
}

MSDN上的一个例子
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
Pascmio影碟机是啥牌子
阳光幼儿园(襄阳襄州)地址在哪,我要去那里办
从银行里面贷款1800元。15年以后要付多少利息
当兵的人回来探家时候可以穿军装吗?
苏J191S2车号如何
360强行删除的原理
求一部还未上映电影名称,是讲水手们大战海里
如何在SpringBoot中使用JSP
无限什么情的成语
excel中如何实现:如果A1不为空并且B1也不为
四个词猜一样东西
送钥匙圈是什么意思
有没有大神帮我看一下,里面这只灰文是公的还
短线高手怎样在尾盘收盘价中找黑马股
请各位大神弄出你们知道的“罗世强”这个名字
推荐资讯
求果宝特攻人物星座
文迪家居地址在什么地方,想过去办事
以‘选择’为题议论文,不少于600字
翻译They turned most of their main players
移动宽带20兆的好用吗?快不快的?
你好 我要去美国探望在美读研得儿子 我的情况
两个月大的小泰迪迷你型的如何喂养
亲们,第一次见未来的嫂子,送什么见面礼好了
《Limbo》第23关的解法。
5 岁以下的小宝宝带墨镜对眼睛有害吗
探墓风云神通怎么提升
f-meansure和f-score 两个不一样吗
手机登qq时,显示手机磁盘不足,清理后重新登
刺客的套装怎么选啊?