邯郸教学仪器设备公司:知道CBitMap指针,怎样用DrawDibDraw将图绘制到屏幕上

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/29 16:31:47
我要将内存位图绘制到屏幕上,以前使用了stretchblt但很慢,(因为我对内存DC设置新的坐标系,所以不能使用bitblt函数),下面是我的代码,在运行中会出现异常,请大家帮忙看看是什么原因,该怎么修改。(中间参考了网上的代码,但不知道为什么这样写) 谢谢!
void CCurveB::CopyBitToDC(CDC *dc,CBitmap *mBitMap)
{
BITMAP bm;
BITMAPINFOHEADER bi;
mBitMap->GetObject(sizeof(bm),(LPSTR)&bm);

bi.biSize = sizeof(BITMAPINFOHEADER);
bi.biWidth = bm.bmWidth;
bi.biHeight = bm.bmHeight;
bi.biPlanes =1;
bi.biBitCount = bm.bmPlanes * bm.bmBitsPixel;
bi.biSizeImage = 0;
bi.biCompression = BI_RGB;//压缩模式为没有压缩
bi.biXPelsPerMeter = 0;
bi.biYPelsPerMeter = 0;
bi.biClrUsed = 0;
bi.biClrImportant =0;

int nColor = (1<<bi.biBitCount);
if (nColor > 256) {
nColor = 0;
}
int dwLen = bi.biSize + nColor * sizeof(RGBQUAD);

BITMAPINFO bh;
HDC hDC = GetDC(NULL);
bh.bmiHeader = bi;
BOOL t = GetDIBits(hDC,(HBITMAP)mBitMap->GetSafeHandle(),0L,(DWORD)bi.biHeight
,NULL,(LPBITMAPINFO)&bh,(DWORD)DIB_RGB_COLORS);
dwLen +=bh.bmiHeader.biSizeImage;//不知道怎么计算大小
byte* bits = new byte[bh.bmiHeader.biSizeImage];
t = GetDIBits(hDC,(HBITMAP)mBitMap->GetSafeHandle(),0L,(DWORD)bi.biHeight
,bits,(LPBITMAPINFO)&bh,(DWORD)DIB_RGB_COLORS);

HDRAWDIB hdd = DrawDibOpen();
t = DrawDibDraw(hdd,dc->GetSafeHdc(),m_OwnRect.left,m_OwnRect.top,m_OwnRect.Width(),m_OwnRect.Height(),
&bh.bmiHeader,bits,0,m_YMax,m_XMax,-m_YMax*2,DDF_SAME_DRAW );//此函数出现访问越限异常
delete [] bits;
}