c++ - CreateCompatibleBitmap 在 Windows Mobile 6 上失败

标签 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);

最佳答案

我没有做过任何 Windows CE/Windows Mobile 编程,但我处理过 similar problem (CreateCompatibleBitmapERROR_NOT_ENOUGH_MEMORY 而失败)在桌面 Windows 中。显然,从我在网上环顾四周所知道的情况来看,Windows 可能会对设备相关位图的可用内存实现全局限制。 (例如,某些视频驱动程序可能会选择将与设备相关的位图存储在视频 RAM 中,在这种情况下,您会受到视频卡上的 RAM 容量的限制。)参见,例如,this thread .据我所知,这些限制是由各个视频卡或驱动程序决定的;一些计算机的存储空间实际上可能是无限的,而其他计算机可能有严格的限制。

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

关于c++ - CreateCompatibleBitmap 在 Windows Mobile 6 上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3235815/

相关文章:

c++ - 改变 switch() 中的数据,累积

android - 发布未知位图引用 - 在 android 中设置标记

c# - 从位图数组创建大位图的快速方法?

c++ - MFC C++ LNK 2019 错误

c++ - Windows MFC 宏

c++ - 在 Windows 下,以相同的对话框 ID 打开 2 个 Windows 是否有效

c++ - 为什么 C++ 不需要 "new"语句来初始化 std::vector?

c++ - 无法分配给 mapType::const_iterator? ("no operator = matches")

c++ - 通过强制转换 nullptr 获取成员变量的偏移量

c++ - Gdiplus::Bitmap 到 BYTE 数组?