网上到处都是说的用CMemFile用法,我用了一个小时调试,结果CMemFile获取的文件都是空长度,不知道为什么,我改为CFile方式直接调试通过


CFile cbfBmp;
cbfBmp.Open( _T("xx.xxx"), CFile::modeRead);
int iBmpSize = cbfBmp.GetLength();
HGLOBAL hMemBmp = GlobalAlloc(GMEM_FIXED, iBmpSize);
IStream* pStmBmp = NULL;
CreateStreamOnHGlobal(hMemBmp, FALSE, &pStmBmp);

BYTE* pbyBmp = (BYTE *)GlobalLock(hMemBmp);
cbfBmp.SeekToBegin();
cbfBmp.Read(pbyBmp, iBmpSize);

 

Image *image = Image::FromStream(pStmBmp);

CClientDC dc(this);
Graphics graphics(dc.m_hDC);//通过设备描述表句柄实例化一个 gdi+ Graphics 类成员
graphics.DrawImage(image,0,0);

相关文章:

  • 2021-10-29
  • 2022-12-23
  • 2022-03-03
  • 2021-11-29
  • 2022-12-23
  • 2022-12-23
  • 2022-01-24
猜你喜欢
  • 2021-10-07
  • 2022-02-19
  • 2022-12-23
  • 2021-05-29
  • 2021-06-10
相关资源
相似解决方案