
在项目的使用过程中,用户偶尔会反映系统的打印功能不能正常使用了,打印出来的页面是空白的。stretchblt经过一翻调查之后,觉的问题很可能出在了StretchBlt上面,貌这个函数具有设备依赖性,并不会被所有的打印机驱动支持。随后将其换掉,采用与设备无关的StretchDIBits,大致代码如下:
//---------------------------------------------------------------
void *lpBits = 0;
int biSizeImage = bm.bmWidthBytes * bm.bmHeight;
lpBits = malloc( biSizeImage );
bitmap.GetBitmapBits( biSizeImage, lpBits );
BITMAPINFO BitmapInfo;

BitmapInfo.bmiHeader.biSize = sizeof( BITMAPINFOHEADER );
BitmapInfo.bmiHeader.biWidth = bm.bmWidth;
BitmapInfo.bmiHeader.biHeight = -bm.bmHeight;
BitmapInfo.bmiHeader.biPlanes = 1;
BitmapInfo.bmiHeader.biBitCount = 32;
BitmapInfo.bmiHeader.biCompression = BI_RGB;
BitmapInfo.bmiHeader.biClrUsed = 0;
BitmapInfo.bmiHeader.biSizeImage = 0;
BitmapInfo.bmiHeader.biXPelsPerMeter = 0;
BitmapInfo.bmiHeader.biYPelsPerMeter = 0;
BitmapInfo.bmiHeader.biClrImportant = 0;
StretchDIBits( *pDC, iOffset_X, iOffset_Y, iBitMap_X, iBitMap_Y, 0, 0, bm.bmWidth, bm.bmHeight, lpBits, &BitmapInfo, DIB_RGB_COLORS, SRCCOPY );
//------------------------------------------------------------------
其中要注意的地方:
1) biSizeImage的大小获取是bm.bmWidthBytes * bm.bmHeight;而不是bm.bmWidth*bm.bmHeight。stretchblt
2)BitmapInfo.bmiHeader.biHeight = -bm.bmHeight;注意是负,如果赋正的话打印内容会完全反过来。
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-26778-1.html
军事委员会约你今晚密谈
坐等上映