Windows Mobile读取位图资源的像素数据问题

来源:互联网 发布:网络的正面影响有哪些 编辑:程序博客网 时间:2024/05/22 20:28

平台:
windows mobile6.5(应该也适用Windows CE),VS2008


问题:

位图资源中已经有个叫IDB_BITMAP1的位图,想获得它的像素数据(即unsigned char类型的一块内存数据),

在PC上的方法:

m_bitmap.LoadBitmap(IDB_BITMAP1); // 加载位图资源, m_bitmap为CBitmap类型

BITMAP bmStruct;

m_bitmap.GetBitmap(&bmStruct);

// bmStruct.bmWidth和bmStruct.bmHeight 为位图资源的尺寸

// bmStruct.bmBits 为像素数据块

但是:在windows mobile平台上可以获得bmStruct.bmWidth和bmStruct.bmHeight 的正确值,但是bmStruct.bmBits始终为NULL!


解决方法:使用FindResource(),LoadResource()等API

m_pBoxData = NULL; // unsigned char*unsigned char *dataBuf = NULL; // total memory block, including image headerDWORD dwBufSize = 0; // size of total memory blockHRSRC hrc = FindResource(AfxGetResourceHandle(),MAKEINTRESOURCE(IDB_BITMAP3),RT_BITMAP);HGLOBAL hGlobal = LoadResource(NULL,hrc);dwBufSize = ::SizeofResource(NULL,hrc); // BITMAP(imagedata+inforhead(40bytes,fixed))dataBuf = (PBYTE)::LockResource(hGlobal); // imagedata pointerm_pBoxData = new unsigned char[dwBufSize-40];// -40bytes(imageheader)memcpy(m_pBoxData, dataBuf, sizeof(unsigned char)*(dwBufSize-40)); // copyFreeResource(hGlobal);BITMAP tmpBM;m_bitmapBox.GetBitmap(&tmpBM);// obtain the width and height of the bmp imagem_bmpImageWidth = tmpBM.bmWidth;m_bmpImageHeight = tmpBM.bmHeight;

参考:http://hi.baidu.com/gengyit/blog/item/5785a5fe8181f4f1fc037f91.html#0



原创粉丝点击