tags:

views:

124

answers:

3

Hi all,

I want to load a jpg file. I tried to use the LoadImage function but it returns NULL if my image is not bmp. What can I do? Here is my code:

hBitmap =(HBITMAP)LoadImage(0, L"D:\\1.jpg", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE).
+2  A: 

You can have a look at WIC.

Windows Imaging Component (WIC) API enables applications to work with all common image formats. It allows developers to not have to understand intricate details of the image formats they work with. WIC has built-in support for popular formats such as JPEG, PNG, TIFF, and GIF as well as an extensibility model so that developers can create their own WIC decoder and encoder (CODEC) and get platform level support for their image format. WIC is available on Windows XP (SP2 and greater), Windows Vista, Windows Server, and Windows 7.

Gregory Pakosz
+1  A: 

Use GDI+, it has a JPEG decoder. Start that ball rolling with #include <gdiplus.h> and a small tutorial to know how to use the Image class and GdiplusStartup properly.

Hans Passant
A: 

If you want to support really old stuff (Win9x etc,) IPicture / OleLoadPicture is your best bet

Anders