Page 2 of 2
Re: How to use the FreeImage DLL?
Posted: Mon Sep 28, 2009 12:34 pm
by Shardik
applePi wrote:is it possible to display animated gifs,...
There exist different approaches to display animated GIFs:
- Using the WebGadget
http://www.purebasic.fr/english/viewtopic.php?t=3817 (from PB in 2002

)
- Using the ATL.DLL
http://www.purebasic.fr/german/viewtopic.php?t=4082 (from mueckerich)
- using external DLLs like FreeImage.DLL or others
localmotion even demonstrated how to load and display each single GIF
frame solely with PB:
http://www.purebasic.fr/english/viewtopic.php?t=27575
Re: How to use the FreeImage DLL?
Posted: Mon Sep 28, 2009 12:41 pm
by srod
There is also an ActiveX control bundled up with COMatePLUS which shows animated gifs etc.

Re: How to use the FreeImage DLL?
Posted: Mon Sep 28, 2009 1:01 pm
by Shardik
srod wrote:There is also an ActiveX control bundled up with COMatePLUS which shows animated gifs etc.
Sorry, srod, for the omission. I am just getting old...

Even the older COMate and PureDispHelper libs contained an example code for animated GIFs from Kiffi...
Re: How to use the FreeImage DLL?
Posted: Mon Sep 28, 2009 1:05 pm
by srod
No need to aplogise; indeed there is nothing to apologise for.

I was just adding yet another option. Admittedly, I'd probably go with the web-gadget option myself.

Re: How to use the FreeImage DLL?
Posted: Fri Apr 15, 2011 7:35 am
by mskuma
I need to write a JPEG using 4:2:2 subsampling (the PB JPEG lib seems to write at 4:4:4 all the time) so I'm come to the FreeImage lib to help me write out an JPEG image created in PB using CreateImage etc (e.g. see below). However the pointer to the image provided by PB seems to be not compatible with the one expected by FreeImage. I'm not so familiar with PB's internal image format. I wonder if anyone's had any experience to save an image using FreeImage like how I'm trying it. I'd be grateful for a suggestion.
Code: Select all
IncludePath "FreeImage\"
IncludeFile "RW_FreeImage_Inc.pb"
UsePNGImageDecoder()
FreeImage_Initialise()
; Create a temporary image
comp = CreateImage(#PB_Any, 1024, 576, 32)
; load background & image to overlay
image1 = LoadImage(#PB_Any, "image1.png")
image2 = LoadImage(#PB_Any, "image2.png")
; every drawing operation must be done between "StartDrawing" and "StopDrawing"
StartDrawing(ImageOutput(comp))
DrawImage(ImageID(image1), 0, 0)
DrawAlphaImage(ImageID(image2), 0, 0, 255)
StopDrawing()
; save as 4:2:2 JPEG using FreeImage
If comp
; newcomp = FreeImage_ConvertTo24Bits(comp) ; probably needed later to downconvert 32 to 24 bits prior to saving
If FreeImage_Save(#FIF_JPEG, comp, "c:\temp\test.jpg", #JPEG_SUBSAMPLING_422) ; <- my problem is comp is causing an error
Debug "free image save: success!"
Else
Debug "free image save: fail!"
EndIf
EndIf
FreeImage(comp)
FreeImage(image1)
FreeImage(image2)
FreeImage_DeInitialise()
Re: How to use the FreeImage DLL?
Posted: Fri Apr 15, 2011 8:05 am
by c4s
Code: Select all
If FreeImage_Save(#FIF_JPEG, ImageID(comp), "c:\temp\test.jpg", #JPEG_SUBSAMPLING_422)

Re: How to use the FreeImage DLL?
Posted: Fri Apr 15, 2011 8:13 am
by mskuma
Thanks c4s, I tried that before - I get an 'invalid memory address' error when I try ImageID(..)
Re: How to use the FreeImage DLL?
Posted: Fri Apr 15, 2011 11:57 am
by mskuma
I found the solution
here under the section
"How do I convert a HBITMAP to a FreeImage image ?"
This code needs to be inserted after StopDrawing()
Code: Select all
If comp
bm.BITMAP
GetObject_(ImageID(comp), SizeOf(BITMAP), @bm)
dib = FreeImage_Allocate(bm\bmWidth, bm\bmHeight, bm\bmBitsPixel)
; the GetDIBits function clears the biClrUsed And biClrImportant BITMAPINFO members (dont't know why)
; so we save these infos below. This is needed for palettized images only.
; nColors = FreeImage_GetColorsUsed(dib)
dc = GetDC_(#Null)
success = GetDIBits_(dc, ImageID(comp), 0, FreeImage_GetHeight(dib), FreeImage_GetBits(dib), FreeImage_GetInfo(dib), #DIB_RGB_COLORS)
ReleaseDC_(#Null, dc);
; restore BITMAPINFO members
; *bmInfo.bitmapinfo = FreeImage_GetInfoHeader(dib)
; *bmInfo\bmiHeader\biClrUsed = nColors
; *bmInfo\bmiHeader\biClrImportant = nColors
EndIf
The parts I've commented out are not needed except perhaps for the case indicated in the original comments.