png转CBitmap
网络是个坑人的地方,需要实践!
// 加载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 }