位图问题,高分赠送,up 者有分 在OnPaint()中用LoadImage()就可以了。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 首先得到对话框的设备环境CDC * dc;dc=GetDC(); //得到对话框的设备环境CDC dcMemory; dcMemory.CreateCompatibleDC(dc); //得到与对话框设备环境相兼容的内DCbitmap=new CBitmap();HBITMAP hbitmap;//装载图片hbitmap=(HBITMAP)::LoadImage(NULL,"C:\\pan.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);if(hbitmap) //成功{ bitmap->Attach(hbitmap);}else{ //出错。。返回 AfxMessageBox("打开图像文件出错"); return;} dcMemory.SelectObject(bitmap); dc->BitBlt(0,0,300,300,&dcMemory,0,0,SRCCOPY);//把内存中的图像复制到对话框DC中去这样,你显示的位图在(0,0)点的位置你想要显示在指定位置作为中心,应先得到位图的大小 //取得图像的大小 long bmWidth,bmHeight; //图像的宽度,和高度 BITMAP bm; bitmap->GetBitmap(&bm); bmWidth=bm.bmWidth; bmHeight=bm.bmHeight;这样你就可以算出开始显示点的位置了好了 http://www.vckbase.com/bbs/prime/viewprime.asp?id=96 谢谢,可是我该怎么把她显示在指定的位置呢?LoadImage()中没有这样的参数呀? 假设你要把ID_YOURBITMAP的bitmap画在中心点是POINT point上:void CYourDialog::OnPaint() { CPaintDC dc(this); CBitmap bmp; BOOL bSucc = bmp.LoadBitmap(ID_YOURBITMAP); if(!bSucc) return; BITMAP bm; bmp.GetObject(sizeof(BITMAP), &bm); CDC dcMem; BOOL bSucc = dcMem.CreateCompatibleDC(&dc); if(!bSucc) return; int x = point.x - (bm.bmWidth / 2); int y = point.y - (bm.bmWidth / 2); dcMem.SelectObject(&bmp); dc.BitBlt(x, y, bm.bmWidth, bm.bmHeight, &dcMem, 0, 0, SRCCOPY); bmp.DeleteObject();} sorry,上面有一句错了,应该是这样:int y = point.y - (bm.bmHeight / 2); sorry,上面有一句错了,应该是这样:int y = point.y - (bm.bmHeight / 2); 上面的代码有一点点小问题,就是在第二个不成功return之前,应该释放bmp的资源。修改一下,完整的代码应该是这样:void CYourDialog::OnPaint() { CPaintDC dc(this); CDC dcMem; BOOL bSucc = dcMem.CreateCompatibleDC(&dc); if(!bSucc) return; CBitmap bmp; BOOL bSucc = bmp.LoadBitmap(ID_YOURBITMAP); if(!bSucc) return; BITMAP bm; bmp.GetObject(sizeof(BITMAP), &bm); int x = point.x - (bm.bmWidth / 2); int y = point.y - (bm.bmWidth / 2); dcMem.SelectObject(&bmp); dc.BitBlt(x, y, bm.bmWidth, bm.bmHeight, &dcMem, 0, 0, SRCCOPY); bmp.DeleteObject();} 不好意思,那句还是忘了改了:int y = point.y - (bm.bmHeight / 2); 不好意思,那句还是忘了改了:int y = point.y - (bm.bmHeight / 2); 如何编译《windows程序设计》中的showbit程序 刚使用vc60编辑,为什么不能直接使用控件名字而要绑定一个变量 请教,有谁做过虚拟数控机床系统吗? 心情不错散分! 请问如何搜索文件夹下的文件包括子文件夹 MFC里对话框添加菜单栏的问题 请教各位大侠怎么改变对话框中文本框内的字体大小及怎么居正中 编译问题 如何用vc实现不同数据库间的转换? 正在调试一个多线程程序,突然想到在调试时按下pause键后程序停在何处? (c++)带数组的函数如何在主函数中调用?/(请大侠举例) 如何给对话框加一个菜单?
CDC * dc;
dc=GetDC(); //得到对话框的设备环境
CDC dcMemory;
dcMemory.CreateCompatibleDC(dc); //得到与对话框设备环境相兼容的内DC
bitmap=new CBitmap();
HBITMAP hbitmap;
//装载图片
hbitmap=(HBITMAP)::LoadImage(NULL,"C:\\pan.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
if(hbitmap) //成功
{
bitmap->Attach(hbitmap);
}
else
{ //出错。。返回
AfxMessageBox("打开图像文件出错");
return;
}
dcMemory.SelectObject(bitmap);
dc->BitBlt(0,0,300,300,&dcMemory,0,0,SRCCOPY);//把内存中的图像复制到对话框DC中去
这样,你显示的位图在(0,0)点的位置
你想要显示在指定位置作为中心,应先得到位图的大小
//取得图像的大小
long bmWidth,bmHeight; //图像的宽度,和高度
BITMAP bm;
bitmap->GetBitmap(&bm);
bmWidth=bm.bmWidth;
bmHeight=bm.bmHeight;
这样你就可以算出开始显示点的位置了好了
{
CPaintDC dc(this); CBitmap bmp;
BOOL bSucc = bmp.LoadBitmap(ID_YOURBITMAP);
if(!bSucc) return;
BITMAP bm;
bmp.GetObject(sizeof(BITMAP), &bm); CDC dcMem;
BOOL bSucc = dcMem.CreateCompatibleDC(&dc);
if(!bSucc) return; int x = point.x - (bm.bmWidth / 2);
int y = point.y - (bm.bmWidth / 2); dcMem.SelectObject(&bmp);
dc.BitBlt(x, y, bm.bmWidth, bm.bmHeight, &dcMem, 0, 0, SRCCOPY); bmp.DeleteObject();
}
int y = point.y - (bm.bmHeight / 2);
int y = point.y - (bm.bmHeight / 2);
void CYourDialog::OnPaint()
{
CPaintDC dc(this); CDC dcMem;
BOOL bSucc = dcMem.CreateCompatibleDC(&dc);
if(!bSucc) return; CBitmap bmp;
BOOL bSucc = bmp.LoadBitmap(ID_YOURBITMAP);
if(!bSucc) return;
BITMAP bm;
bmp.GetObject(sizeof(BITMAP), &bm); int x = point.x - (bm.bmWidth / 2);
int y = point.y - (bm.bmWidth / 2); dcMem.SelectObject(&bmp);
dc.BitBlt(x, y, bm.bmWidth, bm.bmHeight, &dcMem, 0, 0, SRCCOPY); bmp.DeleteObject();
}