Recently i started to develop a small program wich needs to show and manipulate som images. Since i didnt want to spend time trying to write my own routines for this i found a nice image library called FreeImage.

However, when i try to load an image from disk and try to add it to a imagelist it isnt added. Appearently its expecting a different format/handle. I have tried adding the same image as a resource and load it using 'LoadBitmap' wich works without problems. I can also add the image to for ex. main windows background using message 'WM_PAINT' and function 'SetDIBitstodevice'. But how can i add it to an imagelist?

Perhaps noone have used this library or dont think im making any sence at all. Hopefully someone here can help me in the right direction. I have never used alot of the GDI api before, so i am greatfull for any help you can give me. Maybe you know another lib? i need support for .bmp/.jpg/.png and scaling/brightness/contrast functions.

FreeImage Home:

Thanks in advance,
Posted on 2004-05-30 10:33:19 by mojoo
I finally found a solution to my problem...so one of the mods can just delete this thread.

: : mojoo : :
Posted on 2004-05-30 11:05:06 by mojoo
maybe you can post your solution here
Posted on 2004-05-30 12:05:51 by comrade
Thanks for pointing that out Comrade! I should have written down the solution for other curious minds. The problem was that FreeImage gives you a FIBITMAP handle in return when loading pictures. This handle is only supported by FreeImage functions (to my knowledge). So we need to convert FIBITMAP to a HBITMAP in order to e.g. display it in a 'STATIC' control or use it in an 'ImageList'.

inv GetDC, 0
mov hDCBitmap, eax
inv FreeImage_Load, FIF_JPEG, 'c:\my_pic.jpg', JPEG_FAST [COLOR=green];// load file from disk[/COLOR]
inv FreeImage_GetInfo, hFIBitmap [COLOR=green];// returns pointer to BITMAPINFO structure[/COLOR]
mov pBMPInfo, eax
inv FreeImage_GetBits, hFIBitmap [COLOR=green];// returns pointer to data-bits in image[/COLOR]

[COLOR=green];// Convert image type from FIBITMAP to HBITMAP[/COLOR]
inv CreateDIBitmap, \
hDCBitmap, \
dword ptr [pBMPInfo.BITMAPINFO.bmiHeader], \
eax, \
pBMPInfo, \
mov hBitmap, eax

[COLOR=green] ;// Now we can use this to show an image inside a STATIC control or whatever we please[/COLOR]
inv SendMessage, hSTCtrl, STM_SETIMAGE, IMAGE_BITMAP, hBitmap
inv ReleaseDC, hWnd, hDCBitmap
inv FreeImage_Unload, hFIPBitmap
inv DeleteObject, hBitmap

Thanks for tuning in,
Posted on 2004-06-01 03:57:59 by mojoo
Looks like a nice library, too bad it's GPL might have found it useful otherwise.
Posted on 2004-06-01 08:59:41 by donkey

Looks like a nice library, too bad it's GPL might have found it useful otherwise.

The library itself works very well and provides alot of functions. The GPL license is unfortante depending on use. However, for my usage at this time it doesnt give me a problem.
Posted on 2004-06-02 02:54:56 by mojoo