CreateCompatibleBitmap 在 Windows mobile 6 上失败

发布于 2024-09-09 09:21:19 字数 1281 浏览 5 评论 0原文

我正在 Visual Studio 2008 下将应用程序从 Windows Mobile 2003 移植到 Windows Mobile 6。目标设备具有 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);

I'm porting an application from Windows Mobile 2003 to Windows Mobile 6, under Visual Studio 2008. The target device has a VGA resolution screen, and I was surprised to find that the following code fails;

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);
 }

The return code from CreateCompatibleBitmap is 8, which translates to 'Not enough memory to process command. nWidth is 350, nHeight is 400, and the display is 16 bits per pixel, so my bitmap is a whopping 280K. The device I'm using has 256mb of program memory, and I've told the linker to reserve 4mb of stack and 64mb of heap. Any ideas what I'm doing wrong, and more importantly a solution? I've been using code similar to the above on Windows CE since CE 2.1 with no problems.

Edit: As per Josh Kelly's post, I moved to device independent bitmaps which works fine on the device. Code is now something like this

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

从此见与不见 2024-09-16 09:21:19

我没有做过任何 Windows CE / Windows Mobile 编程,但我处理过类似问题< /a>(CreateCompatibleBitmapERROR_NOT_ENOUGH_MEMORY 失败)在桌面 Windows 中。显然,根据我在网上查找的情况来看,Windows 可能会对设备相关位图的可用内存实施全局限制。 (例如,某些视频驱动程序可能选择将设备相关位图存储在视频 RAM 中,在这种情况下,您会受到视频卡上 RAM 大小的限制。)例如,请参见 此线程。据我所知,这些限制是由各个显卡或驱动程序决定的;某些计算机的存储实际上可能是无限的,而其他计算机可能有严格的限制。

一种解决方案是使用与设备无关的位图,尽管它们会造成轻微的性能损失。

I haven't done any Windows CE / Windows Mobile programming, but I have dealt with a similar problem (CreateCompatibleBitmap failing with ERROR_NOT_ENOUGH_MEMORY) in desktop Windows. Apparently, from what I've been able to tell from looking around online, Windows may enforce global limitations on the available memory for device dependent bitmaps. (For example, some video drivers may choose to store device dependent bitmaps in video RAM, in which case you're limited by how much RAM is on your video card.) See, for example, this thread. From what I can tell, these limits are determined by the individual video cards or drivers; some computers' storage may be effectively unlimited, others may have strict limits.

One solution is to use device independent bitmaps instead, even though they have a slight performance penalty.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文