从存档中反序列化位图
我的 MFC 应用程序出现问题。当我尝试从存档中反序列化 CBitmap 并创建新的 CBitmap 时,它无法正确加载 CBitmap 的位。
这是代码:
BITMAP bm;
ar >> bm.bmType;
ar >> bm.bmWidth;
ar >> bm.bmHeight;
ar >> bm.bmWidthBytes;
ar >> bm.bmPlanes;
ar >> bm.bmBitsPixel;
int nSize = bm.bmWidth * bm.bmHeight;
bm.bmBits = new BYTE[nSize];
ar.Read(bm.bmBits, nSize);
CBitmap* tmp = new CBitmap;
tmp->CreateBitmapIndirect(&bm);
BITMAP bmi;
tmp->GetBitmap(&bmi);
HBITMAP hNew = (HBITMAP)CopyImage((HBITMAP)(*tmp), IMAGE_BITMAP,
bmi.bmWidth, bmi.bmHeight, LR_CREATEDIBSECTION);
m_bmp.Attach(hNew);
delete tmp;
在我执行 tmp->GetBitmap(&bmi); 之后我在 bmi.bmBits 字段中得到 NULL。
这有什么问题吗?我怎样才能让它发挥作用?
PS 我不能将序列化为 *.bmp 文件。
预先感谢,迈克。
I've got a problem with my MFC app. When I'm trying to deserialize CBitmap from the archive and create new CBitmap, it doesn't properly load CBitmap's bits.
Here's the code:
BITMAP bm;
ar >> bm.bmType;
ar >> bm.bmWidth;
ar >> bm.bmHeight;
ar >> bm.bmWidthBytes;
ar >> bm.bmPlanes;
ar >> bm.bmBitsPixel;
int nSize = bm.bmWidth * bm.bmHeight;
bm.bmBits = new BYTE[nSize];
ar.Read(bm.bmBits, nSize);
CBitmap* tmp = new CBitmap;
tmp->CreateBitmapIndirect(&bm);
BITMAP bmi;
tmp->GetBitmap(&bmi);
HBITMAP hNew = (HBITMAP)CopyImage((HBITMAP)(*tmp), IMAGE_BITMAP,
bmi.bmWidth, bmi.bmHeight, LR_CREATEDIBSECTION);
m_bmp.Attach(hNew);
delete tmp;
After I do tmp->GetBitmap(&bmi); I get NULL into bmi.bmBits field.
What's wrong with that? How can I make it work?
P.S. I mustn't use serialization into *.bmp file.
Thanks in advance, Mike.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您可以更改序列化,这将起作用,
bmp
是HBITMAP
:If you can change your serialization this will work,
bmp
isHBITMAP
: