从文件中加载位图,双缓冲显示
来源:互联网 发布:数据科学入门 pdf下载 编辑:程序博客网 时间:2024/06/05 00:46
整个程序的流程是一样的,不明白的,可以看上一篇。
这里主要的 不同是怎样产生CBitmap对象。
从资源中加载是:
CBitmap bmp;
bmp.LoadBitmap(IDB_BITMAP1)从文件中加载是:
CBitmap bitmap;
bitmap.m_hObject=(HBITMAP)::LoadImage(NULL,"test.bmp",IMAGE_BITMAP,500,400,LR_LOADFROMFILE);
这里需要注意的是从文件加载位图,并不是通过调用CBitmap的成员函数完成。
而是使用SDK函数LoadImage,通过将其返回值赋值给CBitmap的成员变量m_hObject而完成对CBitmap的对象的赋值过程。
此处的强制类型可以不使用,使用是强调的意思。
注意: When you no longer need the memory DC, call the function.
完全从文件加载位图,双缓冲代码如下,放在OnDraw(CDC* pDC)函数中即可。 CBitmap bitmap;
bitmap.m_hObject=(HBITMAP)::LoadImage(NULL,"test.bmp",IMAGE_BITMAP,500,400,LR_LOADFROMFILE);
if (bitmap.m_hObject)
{
// Get the size of the bitmap
BITMAP bmpInfo;
bitmap.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(&bitmap);
// 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;
POINT ptstart, ptend;
ptstart.x = ptstart.y = 0;
ptend.x = ptend.y = 500;
dcMemory.MoveTo(ptstart);
dcMemory.LineTo(ptend);
// 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(0, 0, bmpInfo.bmWidth * 2, bmpInfo.bmHeight * 2, &dcMemory,
0, 0, SRCCOPY);
dcMemory.SelectObject(pOldBitmap);
SIZE si;
si.cx = bmpInfo.bmWidth;
si.cy = bmpInfo.bmHeight;
SetScrollSizes(MM_TEXT, si);
}
else
TRACE0("ERROR: Where's IDB_BITMAP1?\n");转自(http://www.cppblog.com/alantop/archive/2008/03/14/44414.html)
这里主要的 不同是怎样产生CBitmap对象。
从资源中加载是:
CBitmap bmp;
bmp.LoadBitmap(IDB_BITMAP1)从文件中加载是:
CBitmap bitmap;
bitmap.m_hObject=(HBITMAP)::LoadImage(NULL,"test.bmp",IMAGE_BITMAP,500,400,LR_LOADFROMFILE);
这里需要注意的是从文件加载位图,并不是通过调用CBitmap的成员函数完成。
而是使用SDK函数LoadImage,通过将其返回值赋值给CBitmap的成员变量m_hObject而完成对CBitmap的对象的赋值过程。
此处的强制类型可以不使用,使用是强调的意思。
注意: When you no longer need the memory DC, call the function.
完全从文件加载位图,双缓冲代码如下,放在OnDraw(CDC* pDC)函数中即可。 CBitmap bitmap;
bitmap.m_hObject=(HBITMAP)::LoadImage(NULL,"test.bmp",IMAGE_BITMAP,500,400,LR_LOADFROMFILE);
if (bitmap.m_hObject)
{
// Get the size of the bitmap
BITMAP bmpInfo;
bitmap.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(&bitmap);
// 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;
POINT ptstart, ptend;
ptstart.x = ptstart.y = 0;
ptend.x = ptend.y = 500;
dcMemory.MoveTo(ptstart);
dcMemory.LineTo(ptend);
// 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(0, 0, bmpInfo.bmWidth * 2, bmpInfo.bmHeight * 2, &dcMemory,
0, 0, SRCCOPY);
dcMemory.SelectObject(pOldBitmap);
SIZE si;
si.cx = bmpInfo.bmWidth;
si.cy = bmpInfo.bmHeight;
SetScrollSizes(MM_TEXT, si);
}
else
TRACE0("ERROR: Where's IDB_BITMAP1?\n");转自(http://www.cppblog.com/alantop/archive/2008/03/14/44414.html)
- 从文件中加载位图,双缓冲显示
- 从文件中加载位图,双缓冲显示
- 从资源中加载显示位图,通过双缓冲的方法显示
- 从资源中加载显示位图,通过双缓冲的方法显示
- 双缓冲显示位图
- 从文件加载位图
- 从文件加载位图
- 双缓冲加载位图 WinCE
- 双缓冲加载位图 WinCE
- 使用双缓冲显示位图
- MFC双缓冲显示位图
- 从文件加载一副位图
- 从文件中加载位图到 CBitmap对象
- mfc 显示位图 与 双缓冲
- LoadBitmap加载位图资源、LoadImage从文件加载位图
- mfc 利用HBITMAP 和CBITMAP 显示位图文件(双缓冲)
- OpenGL加载、显示、截图、保存位图文件
- OpenGL加载与显示Targa位图文件
- spring文件最简单的使用
- IDEA中文项目问题解决小记
- Python 类继承 和 格式化输出
- linux常用命令大全
- 远程调用
- 从文件中加载位图,双缓冲显示
- Fault Injection Testing with TestApi
- 【维护和保养电脑主机需12点注意】
- 【jiasuba】快速关闭WinXP的还原功能有绝招
- 从资源中加载显示位图,通过双缓冲的方法显示
- sscanf函数具体用法
- Python状况:为什么PyPy是Python的未来?
- Hadoop完全分布式配置及常见错误集合
- sgu 552 Database optimization (Map)