【发布时间】: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