网络是个坑人的地方,需要实践!
// 加载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:标签:img,bm,Attach,bmp,HBITMAP,CBitmap,png From: https://www.cnblogs.com/zhangmo/p/16813519.html
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 }