积极答复者
请教Win7全屏游戏时截图黑屏的原因

问题
-
我用GDI API截图时,在Win XP测试正常,但是Win7截图始终要么是桌面,要么黑屏,求解?
void CatchScrBmp(BITMAP &m_bmpBit1,BYTE* &m_pBmpData1,BITMAPINFO &BitmapInfo) { HDC hScrDC, hMemDC; //屏幕,内存设备描述表句柄 HBITMAP hBmp; //位图句柄 int nWidth, nHeight; //屏幕的宽和高 hScrDC = ::CreateDC(_T("DISPLAY"), NULL, NULL, NULL); //创建屏幕设备描述表句柄 hMemDC = ::CreateCompatibleDC(hScrDC); //创建与屏幕设备相兼容的内存设备描述表 //分别得到屏幕的宽和高 nWidth = ::GetDeviceCaps( hScrDC, HORZRES // HORZRES Width, in pixels, of the screen. // VERTRES Height, in raster lines, of the screen. ); nHeight = ::GetDeviceCaps(hScrDC, VERTRES); //创建与屏幕设备相兼容的位图 hBmp = ::CreateCompatibleBitmap( hScrDC, // handle to DC nWidth, // width of bitmap, in pixels nHeight // height of bitmap, in pixels ); ::SelectObject(hMemDC, hBmp); //将位图选入内存设备描述表 //复制屏幕设备描述表到内存设备描述表 ::BitBlt( hMemDC, // handle to destination DC 0, // x-coord of destination upper-left corner 0, // y-coord of destination upper-left corner nWidth, // width of destination rectangle nHeight, // height of destination rectangle hScrDC, // handle to source DC 0, // x-coordinate of source upper-left corner 0, // y-coordinate of source upper-left corner SRCCOPY // raster operation code ); CBitmap Bmp; Bmp.Attach(hBmp);//根据位图句柄,得到位图 BITMAP Bitmap; //位图结构 Bmp.GetBitmap(&Bitmap); //得到位图信息头和位图颜色信息 //位图信息结构,包含位图信息头和位图颜色信息 //位图信息头结构 BitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFO); //本结构所占用的字节数 BitmapInfo.bmiHeader.biWidth = Bitmap.bmWidth; //位图宽度,以像素为单位 BitmapInfo.bmiHeader.biHeight = Bitmap.bmHeight; //位图高度,以像素为单位 BitmapInfo.bmiHeader.biPlanes = 1; //目标设备的级别,必须为1 BitmapInfo.bmiHeader.biBitCount = 24; //每个像素所需的位数,必须为1,4,8,24,32 BitmapInfo.bmiHeader.biCompression = 0; //位图压缩类型,必须为0,1,2 BitmapInfo.bmiHeader.biSizeImage = Bitmap.bmWidthBytes * Bitmap.bmHeight; //位图大小,以字节为单位 BitmapInfo.bmiHeader.biXPelsPerMeter = 0; //位图水平分辨率,每米像素数 BitmapInfo.bmiHeader.biYPelsPerMeter = 0; //位图垂直分辩率,每米象素数 BitmapInfo.bmiHeader.biClrUsed = 0; //位图实际使用的颜色表中的颜色数 BitmapInfo.bmiHeader.biClrImportant = 0; //位图显示过程中重要的颜色数 //位图数据信息 m_pBmpData1 = new BYTE[Bitmap.bmWidthBytes * Bitmap.bmHeight]; //用于保存位图数据的缓冲区 int n = ::GetDIBits( hMemDC, // handle to DC hBmp, // handle to bitmap 0, // first scan line to set Bitmap.bmHeight, // number of scan lines to copy m_pBmpData1, // array for bitmap bits &BitmapInfo, // bitmap data buffer DIB_RGB_COLORS // RGB or palette index ); m_bmpBit1 = Bitmap; //创建了句柄,一定要释放,否则会浪费内存 ::DeleteDC(hScrDC); ::DeleteDC(hMemDC); }
麻烦哪位大神指点一下,具体是什么原因导致
One Code , One Dream !
答案
-
你好,
我认为你的代码没有问题,问题在于Windows的一些配置。有以下几种可能性,供你参考:
1. 显卡驱动程序有问题,建议重新安装显卡驱动程序。
2. 关闭硬件加速试试看。
Damon Zheng
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- 已标记为答案 Damon ZhengModerator 2013年1月25日 10:44
全部回复
-
你好,
我认为你的代码没有问题,问题在于Windows的一些配置。有以下几种可能性,供你参考:
1. 显卡驱动程序有问题,建议重新安装显卡驱动程序。
2. 关闭硬件加速试试看。
Damon Zheng
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- 已标记为答案 Damon ZhengModerator 2013年1月25日 10:44
-
你好,
我暂时将自己的回复标记为答案,如果我的建议不能帮助你,请取消标记。
谢谢你的理解。
Damon Zheng
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.