Load a CBitmap dynamically

前端 未结 8 1785
情深已故
情深已故 2021-02-06 02:59

I have a Bitmap image that i want to load dynamically. But I am unable to load it.

CBitmap bmp;

bmp.LoadBitmap(\"c:\\\\aeimg\");

it does not

8条回答
  •  梦毁少年i
    2021-02-06 03:31

    CBitmap doesn't support directly reading from a .bmp file. You can instead make use of CImage class as suggested in other answers. You'll need to include atlimage.h in your code to make CImage work:

    #include 
    :
    CImage img;
    img.Load (_T("C:\\image.bmp"));
    CBitmap bitmap;
    bitmap.Attach(img.Detach());
    

    Another way is to load the image using LoadImage Win32 API and then attaching CBitmap to that:

    HBITMAP hBitmap = (HBITMAP)LoadImage(NULL,"c:\\image.bmp", 
                                          IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
    if (hBitmap != NULL) 
       bitmap.Attach(hBitmap);
    

提交回复
热议问题