【问题标题】:CreateCompatibleBitmap failing on Windows mobile 6Windows mobile 6 上的 CreateCompatibleBitmap 失败
【发布时间】:2011-03-15 05:31:04
【问题描述】:

我正在将一个应用程序从 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);

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

    • 这看起来很可能是这样,因为 CreateBitMap 也没有工作。我会试试 CreateDIBSection 看看效果如何。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-08
    • 1970-01-01
    • 2010-12-11
    • 1970-01-01
    • 1970-01-01
    • 2010-12-06
    相关资源
    最近更新 更多