Page 1 of 2

BMP to GIF Converter

Posted: Thu May 08, 2008 7:31 pm
by Karbon
I'm looking for a small executable or DLL library I can use to convert BMP format images to GIF.. Anyone know of anything?

Posted: Thu May 08, 2008 8:38 pm
by Inf0Byt3
Hi Karbon,

I don't know if it really helps you, but Progi1984 has created a wrapper for FreeImage. You can find more information here:

http://www.purebasic.fr/english/viewtop ... c&start=30

Posted: Thu May 08, 2008 9:50 pm
by srod
Aye, FreeImage is great and Progi has done a great job.

Code: Select all

IncludeFile "RW_FreeImage_Inc.pb"

dib = FreeImage_Load(#FIF_BMP, "bm1.bmp", #BMP_DEFAULT)
FreeImage_Save(#FIF_GIF, dib, "test.gif",0)

Posted: Thu May 08, 2008 10:02 pm
by Derek
I'm pretty sure you can save GIF's using GDI+.

Posted: Thu May 08, 2008 10:23 pm
by srod
Derek wrote:I'm pretty sure you can save GIF's using GDI+.
You can indeed, I just tried it. :)

Posted: Fri May 09, 2008 12:54 am
by Karbon
Thanks for the pointer to FreeImage.

Are there some GDI+ examples floating around for PB?

Posted: Fri May 09, 2008 2:06 am
by einander
HI Karbon:
Do a search for GDIPLUS

Posted: Fri May 09, 2008 10:45 am
by srod
There are some excellent PB wrappers for the gdi+ library in these forums.

However, if saving to gif is all you are after......

Code: Select all

#GDIPLUS_OK = 0

;-Structures.
  Structure GdiplusStartupInput
    GdiPlusVersion.l 
    *DebugEventCallback.DebugEventProc
    SuppressBackgroundThread.l 
    SuppressExternalCodecs.l 
  EndStructure


;-Imports.
  Import "gdiplus.lib"
    GdiplusStartup(token, *input.GdiplusStartupInput, output) 
    GdiplusShutdown(token)
    GdipCreateBitmapFromFile(filename.p-unicode, *bitmap)
    GdipSaveImageToFile(image, filename.p-unicode, *clsidEncoder.CLSID, *encoderParams)
    GdipDisposeImage(image)
  EndImport


;First initialise gdi+.
  input.GdiplusStartupInput
  input\GdiPlusVersion = 1
  GdiplusStartup(@token, @input, #Null)
  ;Was the initialisation successful?
    If token
      If GdipCreateBitmapFromFile("bm1.bmp", @image) = #GDIPLUS_OK
        GdipSaveImageToFile(image, "test.gif", ?clsid_giff, 0)
        GdipDisposeImage(image)
      EndIf
      ;Tidy up.
        GdiplusShutdown(token)
    EndIf

End

;CLSID for the gdi+ gif encoder.
DataSection
clsid_giff:
  Data.l $557CF402
  Data.w $1A04, $11D3
  Data.b $9A, $73, $00, $00, $F8, $1E, $F3, $2E
EndDataSection

Posted: Fri May 09, 2008 7:51 pm
by Karbon
Thanks!

I can't get FreeImage to create a gif.. I can change FIF_GIF to FIF_JPEG (or any other format) and it works great. If I use GIF it just creates a 4k blank file.

I'm using Progi's wrapper and it looks to be up to date..

Posted: Fri May 09, 2008 7:52 pm
by Karbon
Karbon wrote:Thanks!

I can't get FreeImage to create a gif.. I can change FIF_GIF to FIF_JPEG (or any other format) and it works great. If I use GIF it just creates a 4k blank file.

I'm using Progi's wrapper and it looks to be up to date..
Oh, and FreeImage_IsPluginEnabled(#FIF_GIF) does return 1

Posted: Fri May 09, 2008 8:05 pm
by srod
Strange - works okay here. I have found that I have to convert bitmaps to 24 bit before saving as JPEGs etc. I wonder if the gif plugin requires something similar?

Posted: Fri May 09, 2008 8:12 pm
by Karbon
The exact same source BMP image saves as any other format but GIF just by changing FIF_GIF to FIF_<whatever>

Very strange!

Posted: Fri May 09, 2008 8:12 pm
by srod
Can you e-mail me the image in question? Switching to pm.

Posted: Fri May 09, 2008 8:42 pm
by Karbon
Ah, it works if I first convert the BMP to an 8 bit BMP.

Posted: Fri May 09, 2008 8:44 pm
by srod
Yes, but the color table seems to be a grey scale one here! Is there a way of getting FreeImage() to create a better pallete?