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

已经把原始数据转换为256色的BMP格式的图像返回的是储存BMP图象信息及位数据的内存块句柄现在如何通过这个句柄用OnDraw显示图像?... 已经把原始数据转换为256色的BMP格式的图像 返回的是储存BMP图象信息及位数据的内存块句柄 现在如何通过这个句柄用OnDraw显示图像? 展开
 我来答
匿名用户
2014-02-21
展开全部
// 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上的一个例子
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
AiPPT
2024-09-19 广告
作为北京饼干科技有限公司的工作人员,关于AIPPT免费生成PPT的功能,我可以简要介绍如下:AIPPT是一款基于人工智能技术的PPT制作工具,它为用户提供了免费生成PPT的便捷服务。用户只需简单输入PPT的主题或内容大纲,AIPPT便能智能... 点击进入详情页
本回答由AiPPT提供
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式