jdl
jdl

Reputation: 6323

How can I load a jpg file into CBitmap (visual c++ 6.0)?

How can I load a jpg into a CBitmap where I am using visual c++ 6.0 and don't have access to CImage?

thx

Upvotes: 4

Views: 3946

Answers (5)

Redeye
Redeye

Reputation: 1602

There's no native way I know of. I've always used FreeImage for JPGs and PNGs - it's robust and there's example code in the FAQ on how to load a PNG into an HBITMAP (which works exactly the same for a JPG).

One word of warning from experience - if you're storing your JPG as a resource, make sure you create a "JPG" resource type and store it as that, don't try and add it as a BITMAP resource or you'll have all sorts of problems trying to load it. I know it sounds obvious but it took me a while to figure out.

Upvotes: 1

Mark Ransom
Mark Ransom

Reputation: 308120

CBitmap bmp;
HANDLE h = ::LoadImage(NULL, _T("c:\\MyImage.jpg"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
bmp.Attach(h);

Upvotes: 1

Gautam Jain
Gautam Jain

Reputation: 6849

I would simply call OleLoadPicturePath api to load not just jpg but other common formats also.

After loading it into the IPicture object you can call get_Handle to get the handle to HBITMAP.

Thanks

Upvotes: 2

llama
llama

Reputation: 1651

This kind of conversion is complex so i would reccoment using an external libary, take a look at this.

Upvotes: 1

Roel
Roel

Reputation: 19612

You can't, or at least, there isn't a build-in way. Have a look at CxImage, you can probably get that to work, especially when you only need jpg support.

Upvotes: 1

Related Questions