tags:

views:

400

answers:

5

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 seem to be working. Can someone please help me.

Thanks.

+1  A: 

To load a bitmap from a file, you want to use LoadImage with the LR_LOADFROMFILE flag.

Jerry Coffin
+4  A: 

You can also try something like this:

CImage image;
image.Load(_T("C:\\image.png"));
CBitmap bitmap;
bitmap.Attach(image.Detach());
Nikola Smiljanić
A: 

CImage doesn't work with png last time I tried / checked. Have a look at CxImage - http://www.codeproject.com/KB/graphics/cximage.aspx .

Roel
It supports bmp, jpg, gif and png. http://msdn.microsoft.com/en-us/library/d06f3fhw(VS.80).aspx
Nikola Smiljanić
I had to look it up, and you're correct as far as loading from a file goes. My recollection came from it being impossible to load pngs from the resources, as CImage::LoadFromResource() uses ::LoadImage() while Load() uses GDI+.
Roel
A: 

It could be as simple as you forgetting to escape the backslash. Instead of

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

use

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

Otherwise you're passing an invalid path to the LoadBitmap method.

Stefan
Its does not work even after giving the "c:\\aeimg" path.
Ashish
No need to down-vote, he made a perfectly valid suggestion.
Nikola Smiljanić
+1  A: 
According to CBitmap documentation ,

LoadBitmap() function takes resource identifier of the bitmap or resource id of the bitmap.

You can't specify the path of the bitmap file.


E.g.

MyProject.rc
-------------
MYBMP      BITMAP  "res\myimage.bmp"

and make sure that resource.h does not have any entry of MYBMP otherwise during preprocessing its replaced by id and ultimately LoadBitmap() will fail since application can't locate the resource as FindResource() fails. 
Now do this : 

CBitmap bmp;
bmp.LoadBitmap(L"MYBMP");

it will definately load the bitmap..............
Ashish