//Load a bmp file, change its color and display the changed bmp in view
//LoadImage GetDIBits SetDIBitsvoid CViewBmpView::OnDraw(CDC* pDC)
{//load bmp file:"c:\\temp\\test.bmp"
CViewBmpDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
HBITMAP hbmp=(HBITMAP)LoadImage(NULL,"c:\\temp\\test.bmp",IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION|LR_LOADFROMFILE);
CBitmap cbmp;
cbmp.Attach(hbmp);
BITMAP bmp;
cbmp.GetBitmap(&bmp);
cbmp.Detach();
UINT * pData = new UINT[bmp.bmWidth * bmp.bmHeight];
BITMAPINFO bmpInfo;
bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmpInfo.bmiHeader.biWidth = bmp.bmWidth;
bmpInfo.bmiHeader.biHeight = -bmp.bmHeight;
bmpInfo.bmiHeader.biPlanes = 1;
bmpInfo.bmiHeader.biCompression = BI_RGB;
bmpInfo.bmiHeader.biBitCount = 32; GetDIBits(pDC->m_hDC,hbmp,0,bmp.bmHeight,pData,&bmpInfo,DIB_RGB_COLORS);
UINT color, r, g, b;
for(int i = 0; i < bmp.bmWidth * bmp.bmHeight; i ++)
{
color = pData[i];
b = color << 8 >> 24;
g = color << 16 >> 24;
r = color << 24 >> 24;
//note that infact, the r is Blue, b = Red,
r = 0;//mask the blue bits
pData[i] = RGB(r, g, b);
}
SetDIBits(pDC->m_hDC, hbmp,0, bmp.bmHeight, pData,&bmpInfo, DIB_RGB_COLORS);
CDC dcmem;
dcmem.CreateCompatibleDC(pDC);
HGDIOBJ hold=::SelectObject(dcmem.m_hDC,hbmp);
pDC->BitBlt(0,0,bmp.bmWidth,bmp.bmHeight,&dcmem,0,0,SRCCOPY);
::SelectObject(dcmem.m_hDC,hold);
delete pData;
DeleteObject(hbmp);
}
//LoadImage GetDIBits SetDIBitsvoid CViewBmpView::OnDraw(CDC* pDC)
{//load bmp file:"c:\\temp\\test.bmp"
CViewBmpDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
HBITMAP hbmp=(HBITMAP)LoadImage(NULL,"c:\\temp\\test.bmp",IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION|LR_LOADFROMFILE);
CBitmap cbmp;
cbmp.Attach(hbmp);
BITMAP bmp;
cbmp.GetBitmap(&bmp);
cbmp.Detach();
UINT * pData = new UINT[bmp.bmWidth * bmp.bmHeight];
BITMAPINFO bmpInfo;
bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmpInfo.bmiHeader.biWidth = bmp.bmWidth;
bmpInfo.bmiHeader.biHeight = -bmp.bmHeight;
bmpInfo.bmiHeader.biPlanes = 1;
bmpInfo.bmiHeader.biCompression = BI_RGB;
bmpInfo.bmiHeader.biBitCount = 32; GetDIBits(pDC->m_hDC,hbmp,0,bmp.bmHeight,pData,&bmpInfo,DIB_RGB_COLORS);
UINT color, r, g, b;
for(int i = 0; i < bmp.bmWidth * bmp.bmHeight; i ++)
{
color = pData[i];
b = color << 8 >> 24;
g = color << 16 >> 24;
r = color << 24 >> 24;
//note that infact, the r is Blue, b = Red,
r = 0;//mask the blue bits
pData[i] = RGB(r, g, b);
}
SetDIBits(pDC->m_hDC, hbmp,0, bmp.bmHeight, pData,&bmpInfo, DIB_RGB_COLORS);
CDC dcmem;
dcmem.CreateCompatibleDC(pDC);
HGDIOBJ hold=::SelectObject(dcmem.m_hDC,hbmp);
pDC->BitBlt(0,0,bmp.bmWidth,bmp.bmHeight,&dcmem,0,0,SRCCOPY);
::SelectObject(dcmem.m_hDC,hold);
delete pData;
DeleteObject(hbmp);
}
解决方案 »
- 有没有谁能够帮我弄弄MFC?最近要交了!!90%都做好了!!还有一点小问题,请联系我,QQ:381853390,我直接把工程文件发给你!!跪谢!!!!
- CListCtrl(Report),当拖动水平滚动条时,第一列不受影响,一直显示在最左侧,如何实现?? VC/MFC
- new 分配内存报错,郁闷,求指点!!
- 我在做一个类似资源管理器的文档/视图程序。看相关资料,在做一树形视图时(CTreeView),为什么总是要用到CTreeCttl呢?怎么相联系我也不
- 长个裤衩,散分啦!
- 关于CArray的问题
- _beginthreadex 这个函数,在BCB ,DELPHI 和 在 其它平台中 有没有使用。
- 简单多线程参数传递问题,在线等,解决马上给分!!
- 请问:哪有VC6.0英文版下载?
- 在com中对unicode字符进行过写文件处理时碰到的问题
- 在DAO中,用SQL查找一个与时间有关的记录,怎么做?(管理员同志,不要删我好吗)
- 请问使用SDK编程时,如何获得设备句柄
{
CBitmap bmp;
bmp.LoadBitmap(...);CClientDC dc(this);
dc.CreateCompatbileDC(pDC);
dc.SelectObject(&bmp);
pDC->BitBlt(0, 0, bmpWidth, bmpHeigh, &dc, 0, 0, SRCCOPY);
return 1;
}
如在这上面的基础上按下鼠标后,将一个小的位图再画在这个位图上,代码要怎么写,我将代码都放在OnDraw函数中可以,但要实现按下鼠标后再画却不行。在OnLButtonDown中代码是不是有一些要注意的地方,我再开一个新的贴子来给分。
自己写的??
//Creamdog//在给我的留言中留下你的E-mail,并附上你的问题,我会给你详细讲解关于位图的处理方法。/*注意给分*/
怎么回事??
请指教。谢谢