Windows Mobile 6上的CreateCompatibleBitmap失败

时间:2010-07-13 09:30:31

标签: c++ bitmap mfc windows-mobile gdi

我正在将应用程序从Windows Mobile 2003移植到Windows Mobile 6,在Visual Studio 2008下。目标设备具有VGA分辨率屏幕,我惊讶地发现以下代码失败;

CClientDC ClientDC(this);
 CRect Rect;
 GetClientRect(&Rect);

 int nWidth = Rect.Width(),nHeight = Rect.Height();
 CBitmap Temp;
 if (!Temp.CreateCompatibleBitmap(&ClientDC,nWidth,nHeight))
 {
  LogError(elvl_Debug,_T("Error creating bitmap (%s)"),LastSysError());

 } else
 {
  BITMAP bmpinfo;
  Temp.GetBitmap(&bmpinfo);
 }

来自CreateCompatibleBitmap的返回码是8,转换为“没有足够的内存来处理命令”。 nWidth是350,nHeight是400,显示器是每像素16位,所以我的位图是高达280K。我正在使用的设备有256mb的程序存储器,我告诉链接器保留4mb的堆栈和64mb的堆。我有什么不妥的想法,更重要的是解决方案?自从CE 2.1以来,我一直在Windows CE上使用类似于上面的代码,没有任何问题。

编辑:根据Josh Kelly的帖子,我转向了设备无关的位图,它在设备上运行良好。代码现在就是这样的

CClientDC ClientDC(this);
CRect Rect;
GetClientRect(&Rect);
int nWidth = Rect.Width(),nHeight = Rect.Height();
BITMAPINFOHEADER bmi = { sizeof(bmi) }; 
bmi.biWidth = nWidth; 
bmi.biHeight = nHeight; 
bmi.biPlanes = 1; 
bmi.biBitCount = 8; 
HDC hdc = CreateCompatibleDC(NULL); 
BYTE* pbData = 0; 
HBITMAP DIB = CreateDIBSection(hdc, (BITMAPINFO*)&bmi, DIB_RGB_COLORS, (void**)&pbData, NULL, 0);
CBitmap *pTempBitmap = CBitmap::FromHandle(DIB);

1 个答案:

答案 0 :(得分:3)

我还没有完成任何Windows CE / Windows Mobile编程,但是我在桌面Windows中处理了similar problemCreateCompatibleBitmap失败,ERROR_NOT_ENOUGH_MEMORY)。显然,从我在网上浏览时可以看出,Windows可能会对设备相关位图的可用内存强制实施全局限制。 (例如,某些视频驱动程序可能会选择在视频RAM中存储与设备相关的位图,在这种情况下,您受到视频卡上RAM的限制。)例如,请参阅this thread。据我所知,这些限制是由个人视频卡或驱动程序决定的;某些计算机的存储可能实际上是无限制的,其他计算机可能有严格的限制。

一种解决方案是使用与设备无关的位图,即使它们有轻微的性能损失。

相关问题