首页 > 其他分享 >png转CBitmap

png转CBitmap

时间:2022-10-21 15:13:41浏览次数:50  
标签:img bm Attach bmp HBITMAP CBitmap png

网络是个坑人的地方,需要实践!

// 加载bmp文件到CBitmap
bool LoadBmpPic(CString strBmpPath, CBitmap&bmp) { HBITMAP bitmap; try { bmp.Detach(); //从文件路径加载图片 bitmap = (HBITMAP)::LoadImage(NULL, strBmpPath, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE | LR_DEFAULTSIZE); if (bmp.Attach(bitmap)) { return true; } } catch (...) { AfxMessageBox("LoadBmpPic catch!"); return false; } return true; }

  

png转CBitmap:
void LoadPngImageToBmp(CString& path, CBitmap* bm) { CImage img; img.Load(path); #if 0 HBITMAP hbmp = (HBITMAP)img.operator HBITMAP(); bm->DeleteObject(); bm->Attach(hbmp); #elif 1 bm->Attach(img.Detach()); #else HBITMAP hBitmap; hBitmap = img.Detach(); bm->Attach(hBitmap); #endif }

标签:img,bm,Attach,bmp,HBITMAP,CBitmap,png
From: https://www.cnblogs.com/zhangmo/p/16813519.html

相关文章