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

平台:
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 header
DWORD dwBufSize = 0; // size of total memory block
HRSRC 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 pointer
m_pBoxData = new unsigned char[dwBufSize-40];// -40bytes(imageheader)
memcpy(m_pBoxData, dataBuf, sizeof(unsigned char)*(dwBufSize-40)); // copy
FreeResource(hGlobal);
BITMAP tmpBM;
m_bitmapBox.GetBitmap(&tmpBM);// obtain the width and height of the bmp image
m_bmpImageWidth = tmpBM.bmWidth;
m_bmpImageHeight = tmpBM.bmHeight;

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



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值