It is currently Sun Jan 24, 2021 9:56 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Convert Any Image to GIF Format [Windows]
PostPosted: Mon Jan 11, 2021 6:25 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3837
- Code by srod
- Added and Modified by RASHAD
- It can use GDI+ directly to load the image but not TGA
- I hate to see some questions not answered
Have fun
Code:
UsePNGImageDecoder()
UseJPEGImageDecoder()
UseJPEG2000ImageDecoder()
UseTIFFImageDecoder()
UseTGAImageDecoder()

#GDIPLUS_OK = 0

Structure GdiplusStartupInput
  GdiPlusVersion.l
  *DebugEventCallback.DebugEventProc
  SuppressBackgroundThread.l
  SuppressExternalCodecs.l
EndStructure

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

pattern$ = "PNG, BMP, JPEG, TIFF|*.png;*.bmp;*.jpg;*.jpeg;*.tiff|PNG (*.png)|*.png|BMP (*.bmp)|*.bmp|JPEG (*.jpg)|*.jpg|TIFF (*.tif)|*.tif"
Filename$ = OpenFileRequester("Choose an image to convert to GIF:","",pattern$, 0)
If Filename$
  If LoadImage(0,Filename$) = 0
    MessageRequester("Error","Image not loaded",#MB_OK)
    End
  EndIf
EndIf

input.GdiplusStartupInput
input\GdiPlusVersion = 1
GdiplusStartup(@token, @input, #Null)
If token
  If GdipCreateBitmapFromHBITMAP(ImageID(0),0, @image) = #GDIPLUS_OK
    GdipSaveImageToFile(image, GetTemporaryDirectory()+"test.gif", ?clsid_giff, 0)
    GdipDisposeImage(image)
  EndIf
  If IsImage(0)
    FreeImage(0)
  EndIf
  GdiplusShutdown(token)
EndIf
End

DataSection
  clsid_giff:
  Data.l $557CF402
  Data.w $1A04, $11D3
  Data.b $9A, $73, $00, $00, $F8, $1E, $F3, $2E
EndDataSection

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: Convert Any Image to GIF Format [Windows]
PostPosted: Tue Jan 12, 2021 8:49 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon May 09, 2011 9:36 am
Posts: 546
Quote:
- I hate to see some questions not answered


Rashad ... thank you for this Code !

a few questions :

is it possible to set or change a .Gif picture quality value ?
is this Code saving a .Gif at its highest possible picture quality ?

and

Quote:
DataSection
clsid_giff:
Data.l $557CF402
Data.w $1A04, $11D3
Data.b $9A, $73, $00, $00, $F8, $1E, $F3, $2E
EndDataSection


how and where are you getting the clsid values ?

_________________
 
PureBasic .... making tiny electrons do what you want !

"With every mistake we must surely be learning" - George Harrison


Top
 Profile  
Reply with quote  
 Post subject: Re: Convert Any Image to GIF Format [Windows]
PostPosted: Tue Jan 12, 2021 12:03 pm 
Offline
Addict
Addict

Joined: Thu Apr 18, 2019 8:17 am
Posts: 1207
Rashad, thanks, but it seems the GIF image with your code is dithered or something, because the quality is lower than the original code.

(a) Original test image -> https://i.imgur.com/ADfHBip.png
(b) Original code to gif -> https://i.imgur.com/5FeUsRg.png
(c) Your new code to gif -> https://i.imgur.com/t0C6Agl.png

See what I mean? Compare (b) and (c). Can your routine make it look like the (b) image above?

(BTW, I saved the results as PNGs simply out of habit, but the visuals are the same as PNG is lossless).


Top
 Profile  
Reply with quote  
 Post subject: Re: Convert Any Image to GIF Format [Windows]
PostPosted: Tue Jan 12, 2021 12:27 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Apr 05, 2020 11:28 am
Posts: 422
Location: Pandora
With a GIF photo you go back to the computer stone age.
This is how it will look like.
That is normal.
Just have a look in Wikipedia how a GIF works.
I myself don't see any use for a mono frame gif because it has only disadvantages, sorry.

_________________
地球上の平和


Top
 Profile  
Reply with quote  
 Post subject: Re: Convert Any Image to GIF Format [Windows]
PostPosted: Tue Jan 12, 2021 12:31 pm 
Offline
Addict
Addict

Joined: Thu Apr 18, 2019 8:17 am
Posts: 1207
Saki, Rashad's modification of the original code leads to a dithered image. The only difference is that the same original image was converted from a file (b) or from RAM (c). The output should be the same, but the file version is clearly visually superior.


Top
 Profile  
Reply with quote  
 Post subject: Re: Convert Any Image to GIF Format [Windows]
PostPosted: Tue Jan 12, 2021 12:52 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Apr 05, 2020 11:28 am
Posts: 422
Location: Pandora
Hmm, I can't say anything about that.
Gif is devil's work. :wink:
What would be needed would be the full support of PB.
But this is all very complex.
The hype after GIF is largely over again and it will probably disappear again completely, i think

_________________
地球上の平和


Top
 Profile  
Reply with quote  
 Post subject: Re: Convert Any Image to GIF Format [Windows]
PostPosted: Tue Jan 12, 2021 8:44 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3837
Hi VB6_to_PBx

Next are the gdiplus_GUID for different formats
Code:
GUID_ImageEncoderBMP:
  Data.l $557cf400
  Data.w $1a04, $11d3
  Data.b $9a, $73, $00, $00, $f8, $1e, $f3, $2e
GUID_ImageEncoderJPEG:
  Data.l $557cf401
  Data.w $1a04, $11d3
  Data.b $9a, $73, $00, $00, $f8, $1e, $f3, $2e
GUID_ImageEncoderGIF:
  Data.l $557cf402
  Data.w $1a04, $11d3
  Data.b $9a, $73, $00, $00, $f8, $1e, $f3, $2e
GUID_ImageDecoderEMF:
  Data.l $557cf403
  Data.w $1a04, $11d3
  Data.b $9a, $73, $00, $00, $f8, $1e, $f3, $2e
GUID_ImageDecoderWMF:
  Data.l $557cf404
  Data.w $1a04, $11d3
  Data.b $9a, $73, $00, $00, $f8, $1e, $f3, $2e
GUID_ImageEncoderTIFF:
  Data.l $557cf405
  Data.w $1a04, $11d3
  Data.b $9a, $73, $00, $00, $f8, $1e, $f3, $2e
GUID_ImageEncoderPNG:
  Data.l $557cf406
  Data.w $1a04, $11d3
  Data.b $9a, $73, $00, $00, $f8, $1e, $f3, $2e

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: Convert Any Image to GIF Format [Windows]
PostPosted: Wed Jan 13, 2021 6:46 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon May 09, 2011 9:36 am
Posts: 546
RASHAD wrote:
Hi VB6_to_PBx

Next are the gdiplus_GUID for different formats
Code:
GUID_ImageEncoderBMP:
  Data.l $557cf400
  Data.w $1a04, $11d3
  Data.b $9a, $73, $00, $00, $f8, $1e, $f3, $2e
GUID_ImageEncoderJPEG:
  Data.l $557cf401
  Data.w $1a04, $11d3
  Data.b $9a, $73, $00, $00, $f8, $1e, $f3, $2e
GUID_ImageEncoderGIF:
  Data.l $557cf402
  Data.w $1a04, $11d3
  Data.b $9a, $73, $00, $00, $f8, $1e, $f3, $2e
GUID_ImageDecoderEMF:
  Data.l $557cf403
  Data.w $1a04, $11d3
  Data.b $9a, $73, $00, $00, $f8, $1e, $f3, $2e
GUID_ImageDecoderWMF:
  Data.l $557cf404
  Data.w $1a04, $11d3
  Data.b $9a, $73, $00, $00, $f8, $1e, $f3, $2e
GUID_ImageEncoderTIFF:
  Data.l $557cf405
  Data.w $1a04, $11d3
  Data.b $9a, $73, $00, $00, $f8, $1e, $f3, $2e
GUID_ImageEncoderPNG:
  Data.l $557cf406
  Data.w $1a04, $11d3
  Data.b $9a, $73, $00, $00, $f8, $1e, $f3, $2e


thank you Rashad , you are always helpful !
i wish we could Vote or give Stars in this Forum .

_________________
 
PureBasic .... making tiny electrons do what you want !

"With every mistake we must surely be learning" - George Harrison


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 26 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye