[Gambas-user] Is it possible to use a library that uses gb.sdl2 in a graphic project?

Martin Belmonte mbelmonte at belmotek.net
Thu Mar 10 14:10:18 CET 2022


El 10/3/22 a las 13:34, Gianluigi escribió:
>   TIF file into BMP
Hi, I solve the problem using the freeimage library, for that i take the 
code from the Italian forum but i modify it to use as Task class.
Maybe it will be useful for you.

' Gambas class file

'''Images convertion class. To be used in conjunction with gb.Task

Inherits Task

Public sInput As String
Public sOutput As String
Public sThumb As String
Public sMode As String

Library "libfreeimage-3.18.0"

Private Enum FIF_UNKNOWN = -1, FIF_BMP, FIF_ICO, FIF_JPEG, FIF_JNG, 
FIF_KOALA, FIF_LBM, FIF_IFF = 5, FIF_MNG = 6,
   FIF_PBM, FIF_PBMRAW, FIF_PCD, FIF_PCX, FIF_PGM, FIF_PGMRAW, FIF_PNG, 
FIF_PPM, FIF_PPMRAW, FIF_RAS,
   FIF_TARGA, FIF_TIFF, FIF_WBMP, FIF_PSD, FIF_CUT, FIF_XBM, FIF_XPM, 
FIF_DDS, FIF_GIF, FIF_HDR, FIF_FAXG3,
   FIF_SGI, FIF_EXR, FIF_J2K, FIF_JP2, FIF_PFM, FIF_PICT, FIF_RAW

Private Const JPEG_DEFAULT As Integer = 0
Private Const TIFF_DEFAULT As Integer = 0
Private Const PNG_DEFAULT As Integer = 0

' void FreeImage_Initialise(BOOL FI_DEFAULT(FALSE))
' Initialises the library.
Private Extern FreeImage_Initialise(fi_default As Boolean)

' const char * FreeImage_GetCopyrightMessage(void)
' Returns a string containing a standard copyright message.
'Private Extern FreeImage_GetCopyrightMessage() As String

' FIBITMAP * FreeImage_Load(FREE_IMAGE_FORMAT fif, const char *filename, 
int flags FI_DEFAULT(0))
' Load routines. Decodes a bitmap, allocates memory for it and then 
returns it as a FIBITMAP.
Private Extern FreeImage_Load(fif As Integer, filename As String, flags 
As Integer) As Pointer

' BOOL FreeImage_Save(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, const char 
*filename, int flags FI_DEFAULT(0))
' Saves a previously loaded FIBITMAP to a file.
Private Extern FreeImage_Save(fif As Integer, dib As Pointer, filename 
As String, flags As Integer) As Boolean

' void FreeImage_Unload(FIBITMAP *dib)
' Unload routines.
Private Extern FreeImage_Unload(dib As Pointer)

' void FreeImage_DeInitialise(void)
' Deinitialises the library.
Private Extern FreeImage_DeInitialise()

Public Sub Main()

   Dim fbm As Pointer
   Dim bo As Boolean
   Dim hImage As Image
   Dim hThumb As Image

   ' Inizializza la libreria "FreeImage":
   FreeImage_Initialise(False)

   Select sMode
     Case "tiff-jpeg"
       fbm = FreeImage_Load(FIF_TIFF, sInput, TIFF_DEFAULT)
       bo = FreeImage_Save(FIF_JPEG, fbm, sOutput, JPEG_DEFAULT)
       'If bo = False Then Error.Raise("Impossibile salvare l'immagine !")
       If Not Exist(sThumb) Then
         hImage = Image.Load(sOutput)
         hThumb = hImage.Stretch(256, 358).Copy()
         hThumb.Save(sThumb, 10)
         Print "******" & sThumb & "*********"
       Endif

     Case "tiff-bmp"
       fbm = FreeImage_Load(FIF_TIFF, sInput, TIFF_DEFAULT)
       bo = FreeImage_Save(FIF_BMP, fbm, sOutput, BMP_DEFAULT)

     Case "jpeg-png"
       fbm = FreeImage_Load(FIF_JPEG, sInput, JPEG_DEFAULT)
       bo = FreeImage_Save(FIF_PNG, fbm, sOutput, PNG_DEFAULT)

   End Select

   ' Libera la memoria precedentemente allocata e deinizializza la 
libreria "FreeImage":
   FreeImage_Unload(fbm)
   FreeImage_DeInitialise()

End
----------------------
Regards.


More information about the User mailing list