【发布时间】:2011-01-18 09:54:28
【问题描述】:
我正在尝试使用CreateDIBSection。
问题:
在 Windows XP 中,我尝试调用 CreateDIBSection,它返回 NULL 和 GetLastError = 0
当我尝试将屏幕分辨率更改为 2048 x 1536 时,它会返回正确的值。
我测试过这个函数和nMemSize有一定的关系(不一定是小数)。
问题:
是否有任何保证方法可以确保CreateDIBSection 返回正确的值?
nScreenWidth = 1024;
nScreenHeight= 768;
= nScreenWidth*nScreenHeight*3*7
HDC hdc = ::GetDC(hWnd);
m_hBmpMapFile = ::CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, nMemSize, NULL);
BITMAPINFO bmpInfo = {0};
bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmpInfo.bmiHeader.biWidth = nScreenWidth;
bmpInfo.bmiHeader.biHeight = nScreenHeight;
bmpInfo.bmiHeader.biPlanes = 1;
bmpInfo.bmiHeader.biBitCount = 24;
bmpInfo.bmiHeader.biCompression = 0;
bmpInfo.bmiHeader.biSizeImage = nMemSize;
bmpInfo.bmiHeader.biXPelsPerMeter = 0;
bmpInfo.bmiHeader.biYPelsPerMeter = 0;
bmpInfo.bmiHeader.biClrUsed = 0;
bmpInfo.bmiHeader.biClrImportant = 0;
bmpInfo.bmiColors[0].rgbBlue = 204;
bmpInfo.bmiColors[0].rgbGreen = 204;
bmpInfo.bmiColors[0].rgbRed = 204;
bmpInfo.bmiColors[0].rgbReserved = 0;
PVOID pvBits;
m_hBmpAllWstDskWallpaper = ::CreateDIBSection(hdc, &bmpInfo, DIB_RGB_COLORS, &pvBits, m_hBmpMapFile, 0);
【问题讨论】:
-
嗯,目前还不清楚它为什么会失败。我认为你的问题应该是,“为什么 CreateDIBSection 失败了?”。如果你能得到答案,那么你应该能够解决你真正的问题。
-
好的,我已经改了。我认为当 nMemSize 更改为特定数字时,真正的问题是 CreateDIBSection 失败。有时它会失败,说 10000,但是当你将 nMemsize 更改为更大的 20000 时,它会成功。
-
@yyy:发布
bmpinfo.bmiHeader的所有字段。你赋予他们什么价值? -
请提供完整的代码。我们更容易说出(或猜测)问题可能出在哪里。为什么
* 7在nMemSize等式中? -
对不起,我刚刚编辑了。
*3表示 RGB 字节,*7表示屏幕大小的 7 倍。我正在制作一个大的水平全景屏幕。
标签: c++ windows-xp bitmap createdibsection