Differenze tra le versioni di "Creare un file immagine trasparente di tipo GIF con le funzioni del API di GIFLIB"
Da Gambas-it.org - Wikipedia.
(Creata pagina con 'Come si sa, salvare un'immagine in un file di formato ''.GIF'' (''Graphics Interchange Format''), in Gambas non è attualmente possibile. Gambas possiede, sì, risorse per car...') |
|||
(6 versioni intermedie di uno stesso utente non sono mostrate) | |||
Riga 1: | Riga 1: | ||
− | Come si sa, salvare un'immagine in un file di formato | + | Come si sa, salvare un'immagine in un file di formato .GIF (Graphics Interchange Format), in Gambas non è attualmente possibile. Gambas possiede, sì, risorse per caricare file immagine di tipo .gif, ma non per salvarle. |
− | Un aiuto, però, per la generazione di file immagine di tipo | + | Un aiuto, però, per la generazione di file immagine di tipo GIF può giungerci dalle risorse della libreria GIFLIB, la quale consente di caricare, gestire, maniplare, creare ex novo e salvare file immagine in fomato GIF. |
− | Per poter utilizzare al meglio le risorse della libreria | + | Per poter utilizzare al meglio le risorse della libreria GifLib con Gambas, suggeriamo di utilizzare la relativa libreria condivisa: "''libgif.so.7.1.0'' " |
− | + | Mostriamo di seguito un breve esempio per generare ex novo un semplice file immagine trasparente di tipo .gif: | |
− | Mostriamo di seguito un breve esempio per generare | + | <FONT Color=gray>''The GIFLIB distribution is Copyright (c) 1997 Eric S. Raymond |
+ | |||
+ | Permission is hereby granted, free of charge, to any person obtaining a copy | ||
+ | of this software and associated documentation files (the "Software"), to deal | ||
+ | in the Software without restriction, including without limitation the rights | ||
+ | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
+ | copies of the Software, and to permit persons to whom the Software is | ||
+ | furnished to do so, subject to the following conditions: | ||
+ | |||
+ | The above copyright notice and this permission notice shall be included in | ||
+ | all copies or substantial portions of the Software. | ||
+ | |||
+ | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
+ | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
+ | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
+ | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
+ | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
+ | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
+ | THE SOFTWARE.</font> | ||
+ | |||
Private Const QuantitasColori As Integer = 256 | Private Const QuantitasColori As Integer = 256 | ||
Private Const DimMappaColori As Integer = 8 | Private Const DimMappaColori As Integer = 8 | ||
− | Library "libgif:7. | + | Library "libgif:7.1.0" |
Private Enum GIF_ERROR = 0, GIF_OK | Private Enum GIF_ERROR = 0, GIF_OK | ||
Riga 20: | Riga 39: | ||
<FONT Color=gray>' ''GifFileType * EGifOpenFileName(const char *FileName, const bool TestExistence, int *Error)'' | <FONT Color=gray>' ''GifFileType * EGifOpenFileName(const char *FileName, const bool TestExistence, int *Error)'' | ||
− | ' ''Open a new GIF file for write, specified by name.''</ | + | ' ''Open a new GIF file for write, specified by name.''</fonT> |
Private Extern EGifOpenFileName(FileName As String, TestExistence As Boolean, ErrorP As Pointer) As Pointer | Private Extern EGifOpenFileName(FileName As String, TestExistence As Boolean, ErrorP As Pointer) As Pointer | ||
<FONT Color=gray>' ''int EGifPutScreenDesc(GifFileType *GifFile, const int Width, const int Height, const int ColorRes, const int BackGround, const ColorMapObject *ColorMap)'' | <FONT Color=gray>' ''int EGifPutScreenDesc(GifFileType *GifFile, const int Width, const int Height, const int ColorRes, const int BackGround, const ColorMapObject *ColorMap)'' | ||
− | ' ''This routine should be called immediately following the GIF file opening.''</ | + | ' ''This routine should be called immediately following the GIF file opening.''</fonT> |
Private Extern EGifPutScreenDesc(GifFileType As Pointer, wI As Integer, hI As Integer, ColorRes As Integer, BackGround As Integer, ColorMap As Pointer) As Integer | Private Extern EGifPutScreenDesc(GifFileType As Pointer, wI As Integer, hI As Integer, ColorRes As Integer, BackGround As Integer, ColorMap As Pointer) As Integer | ||
<FONT Color=gray>' ''int EGifPutImageDesc(GifFileType *GifFile, const int Left, const int Top, const int Width, const int Height, const bool Interlace, const ColorMapObject *ColorMap)'' | <FONT Color=gray>' ''int EGifPutImageDesc(GifFileType *GifFile, const int Left, const int Top, const int Width, const int Height, const bool Interlace, const ColorMapObject *ColorMap)'' | ||
− | ' ''This routine should be called before any attempt to dump an image - any call to any of the pixel dump routines.''</ | + | ' ''This routine should be called before any attempt to dump an image - any call to any of the pixel dump routines.''</fonT> |
Private Extern EGifPutImageDesc(GifFileType As Pointer, LeftI As Integer, Top As Integer, wI As Integer, hI As Integer, Interlace As Boolean, ColorMap As Pointer) As Integer | Private Extern EGifPutImageDesc(GifFileType As Pointer, LeftI As Integer, Top As Integer, wI As Integer, hI As Integer, Interlace As Boolean, ColorMap As Pointer) As Integer | ||
<FONT Color=gray>' ''int EGifCloseFile(GifFileType *GifFile, int *ErrorCode)'' | <FONT Color=gray>' ''int EGifCloseFile(GifFileType *GifFile, int *ErrorCode)'' | ||
− | ' ''Closes the GIF file.''</ | + | ' ''Closes the GIF file.''</fonT> |
Private Extern EGifCloseFile(GifFileType As Pointer, ErrorCode As Pointer) As Integer | Private Extern EGifCloseFile(GifFileType As Pointer, ErrorCode As Pointer) As Integer | ||
Riga 40: | Riga 59: | ||
Dim Width, Height, err As Integer | Dim Width, Height, err As Integer | ||
Dim MappaColori, fileGIF As Pointer | Dim MappaColori, fileGIF As Pointer | ||
− | |||
− | |||
− | |||
− | |||
− | + | <FONT Color=gray>' ''Impostiamo a piacere le dimensioni in pixel dell'immagine da creare:''</fonT> | |
− | + | Width = 640 | |
− | + | Height = 400 | |
− | |||
− | |||
− | + | MappaColori = GifMakeMapObject(QuantitasColori, Null) | |
− | + | If MappaColori == 0 Then Error.Raise("Impossibile allocare memoria !") | |
− | + | ||
− | + | fileGIF = EGifOpenFileName("''/percorso/del/file.gif''", 0, 0) | |
− | + | If fileGIF == 0 Then Error.Raise("Impossibile creare il file GIF !") | |
− | If EGifCloseFile(fileGIF, 0) = GIF_ERROR Then Error.Raise("Errore nella chiusura del file GIF !") | + | err = EGifPutScreenDesc(fileGIF, Width, Height, DimMappaColori, 0, MappaColori) |
− | + | If err = GIF_ERROR Then Error.Raise("Errore alla funzione 'EGifPutScreenDesc()' !") | |
+ | |||
+ | err = EGifPutImageDesc(fileGIF, 0, 0, Width, Height, False, Null) | ||
+ | If err = GIF_ERROR Then Error.Raise("Errore alla funzione 'EGifPutImageDesc()' !") | ||
+ | |||
+ | If EGifCloseFile(fileGIF, 0) = GIF_ERROR Then Error.Raise("Errore nella chiusura del file GIF !") | ||
+ | |||
'''End''' | '''End''' | ||
− | |||
=Riferimenti= | =Riferimenti= | ||
− | * | + | * http://giflib.sourceforge.net/gif_lib.html |
− | * | + | * http://wwwcdf.pd.infn.it/libgif/index.html |
+ | * http://fossies.org/dox/giflib-5.1.1/index.html |
Versione attuale delle 20:30, 30 nov 2021
Come si sa, salvare un'immagine in un file di formato .GIF (Graphics Interchange Format), in Gambas non è attualmente possibile. Gambas possiede, sì, risorse per caricare file immagine di tipo .gif, ma non per salvarle.
Un aiuto, però, per la generazione di file immagine di tipo GIF può giungerci dalle risorse della libreria GIFLIB, la quale consente di caricare, gestire, maniplare, creare ex novo e salvare file immagine in fomato GIF.
Per poter utilizzare al meglio le risorse della libreria GifLib con Gambas, suggeriamo di utilizzare la relativa libreria condivisa: "libgif.so.7.1.0 "
Mostriamo di seguito un breve esempio per generare ex novo un semplice file immagine trasparente di tipo .gif:
The GIFLIB distribution is Copyright (c) 1997 Eric S. Raymond Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Private Const QuantitasColori As Integer = 256 Private Const DimMappaColori As Integer = 8 Library "libgif:7.1.0" Private Enum GIF_ERROR = 0, GIF_OK ' ColorMapObject * GifMakeMapObject (int ColorCount, const GifColorType * ColorMap) ' Allocate a color map of given size. Private Extern GifMakeMapObject(ColorCount As Integer, ColorMap As Pointer) As Pointer ' GifFileType * EGifOpenFileName(const char *FileName, const bool TestExistence, int *Error) ' Open a new GIF file for write, specified by name. Private Extern EGifOpenFileName(FileName As String, TestExistence As Boolean, ErrorP As Pointer) As Pointer ' int EGifPutScreenDesc(GifFileType *GifFile, const int Width, const int Height, const int ColorRes, const int BackGround, const ColorMapObject *ColorMap) ' This routine should be called immediately following the GIF file opening. Private Extern EGifPutScreenDesc(GifFileType As Pointer, wI As Integer, hI As Integer, ColorRes As Integer, BackGround As Integer, ColorMap As Pointer) As Integer ' int EGifPutImageDesc(GifFileType *GifFile, const int Left, const int Top, const int Width, const int Height, const bool Interlace, const ColorMapObject *ColorMap) ' This routine should be called before any attempt to dump an image - any call to any of the pixel dump routines. Private Extern EGifPutImageDesc(GifFileType As Pointer, LeftI As Integer, Top As Integer, wI As Integer, hI As Integer, Interlace As Boolean, ColorMap As Pointer) As Integer ' int EGifCloseFile(GifFileType *GifFile, int *ErrorCode) ' Closes the GIF file. Private Extern EGifCloseFile(GifFileType As Pointer, ErrorCode As Pointer) As Integer Public Sub Main() Dim Width, Height, err As Integer Dim MappaColori, fileGIF As Pointer ' Impostiamo a piacere le dimensioni in pixel dell'immagine da creare: Width = 640 Height = 400 MappaColori = GifMakeMapObject(QuantitasColori, Null) If MappaColori == 0 Then Error.Raise("Impossibile allocare memoria !") fileGIF = EGifOpenFileName("/percorso/del/file.gif", 0, 0) If fileGIF == 0 Then Error.Raise("Impossibile creare il file GIF !") err = EGifPutScreenDesc(fileGIF, Width, Height, DimMappaColori, 0, MappaColori) If err = GIF_ERROR Then Error.Raise("Errore alla funzione 'EGifPutScreenDesc()' !") err = EGifPutImageDesc(fileGIF, 0, 0, Width, Height, False, Null) If err = GIF_ERROR Then Error.Raise("Errore alla funzione 'EGifPutImageDesc()' !") If EGifCloseFile(fileGIF, 0) = GIF_ERROR Then Error.Raise("Errore nella chiusura del file GIF !") End