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
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);