Differenze tra le versioni di "Sfumare radialmente un'immagine mediante le funzioni esterne del API di ImageMagick"
Da Gambas-it.org - Wikipedia.
Riga 2: | Riga 2: | ||
Per poter fruire in Gambas delle risorse, è necessario avere installata nel sistema e richiamare la seguente libreria condivisa: "''libMagickWand-6.Q16.so.6.0.0'' ". | Per poter fruire in Gambas delle risorse, è necessario avere installata nel sistema e richiamare la seguente libreria condivisa: "''libMagickWand-6.Q16.so.6.0.0'' ". | ||
− | |||
Le risorse di questa libreria ci consentono - fra l'altro - di sfumare un'immagine con un effetto vortice. | Le risorse di questa libreria ci consentono - fra l'altro - di sfumare un'immagine con un effetto vortice. | ||
Riga 8: | Riga 7: | ||
Mostriamo un esempio pratico: | Mostriamo un esempio pratico: | ||
Library "libMagickWand-6.Q16:6.0.0" | Library "libMagickWand-6.Q16:6.0.0" | ||
+ | |||
+ | Private Const MagickPathExtent As Integer = 4096 | ||
+ | |||
+ | Public Struct MagickWand | ||
+ | id As Long | ||
+ | name[MagickPathExtent] As Byte | ||
+ | images As Pointer | ||
+ | image_info As Pointer | ||
+ | exception As Pointer | ||
+ | insert_before As Integer | ||
+ | image_pending As Integer | ||
+ | debug_ As Integer | ||
+ | signature As Long | ||
+ | End Struct | ||
Private Enum MagickFalse = 0, MagickTrue | Private Enum MagickFalse = 0, MagickTrue | ||
Riga 17: | Riga 30: | ||
<FONT Color=gray>' ''MagickWand *NewMagickWand(void)'' | <FONT Color=gray>' ''MagickWand *NewMagickWand(void)'' | ||
' ''Returns a wand required for all other methods in the API.''</font> | ' ''Returns a wand required for all other methods in the API.''</font> | ||
− | Private Extern NewMagickWand() As | + | Private Extern NewMagickWand() As MagickWand |
<FONT Color=gray>' ''MagickBooleanType MagickReadImage(MagickWand *wand,const char *filename)'' | <FONT Color=gray>' ''MagickBooleanType MagickReadImage(MagickWand *wand,const char *filename)'' | ||
' ''Reads an image or image sequence.''</font> | ' ''Reads an image or image sequence.''</font> | ||
− | Private Extern MagickReadImage(wand As | + | Private Extern MagickReadImage(wand As MagickWand, filename As String) As Integer |
<FONT Color=gray>' ''MagickBooleanType MagickRadialBlurImage(MagickWand *wand, const double angle)'' | <FONT Color=gray>' ''MagickBooleanType MagickRadialBlurImage(MagickWand *wand, const double angle)'' | ||
' ''Blurs an image.''</font> | ' ''Blurs an image.''</font> | ||
− | Private Extern MagickRadialBlurImage(wand As | + | Private Extern MagickRadialBlurImage(wand As MagickWand, blur As Float) As Integer |
<FONT Color=gray>' ''MagickBooleanType MagickWriteImages(MagickWand *wand, const char *filename,const MagickBooleanType adjoin)'' | <FONT Color=gray>' ''MagickBooleanType MagickWriteImages(MagickWand *wand, const char *filename,const MagickBooleanType adjoin)'' | ||
' ''Writes an image or image sequence.''</font> | ' ''Writes an image or image sequence.''</font> | ||
− | Private Extern MagickWriteImages(wand As | + | Private Extern MagickWriteImages(wand As MagickWand, filename As String, adjoin As Boolean) As Integer |
<FONT Color=gray>' ''MagickWand *DestroyMagickWand(MagickWand *wand)'' | <FONT Color=gray>' ''MagickWand *DestroyMagickWand(MagickWand *wand)'' | ||
' ''Deallocates memory associated with an MagickWand.''</font> | ' ''Deallocates memory associated with an MagickWand.''</font> | ||
− | Private Extern DestroyMagickWand(wand As | + | Private Extern DestroyMagickWand(wand As MagickWand) As MagickWand |
<FONT Color=gray>' ''void MagickWandTerminus(void)'' | <FONT Color=gray>' ''void MagickWandTerminus(void)'' | ||
Riga 42: | Riga 55: | ||
'''Public''' Sub Main() | '''Public''' Sub Main() | ||
− | Dim bo As | + | Dim bo As Integer |
− | Dim | + | Dim mwand As MagickWand |
Dim fileimmagine, nuovofile As String | Dim fileimmagine, nuovofile As String | ||
− | + | ||
fileimmagine = "<FONT Color=gray>''/percorso/del/file/immagine''</font>" | fileimmagine = "<FONT Color=gray>''/percorso/del/file/immagine''</font>" | ||
nuovofile = "<FONT Color=gray>''/percorso/del/nuovo/file/dell'immagine/spostata''</font>" | nuovofile = "<FONT Color=gray>''/percorso/del/nuovo/file/dell'immagine/spostata''</font>" | ||
Riga 51: | Riga 64: | ||
MagickWandGenesis() | MagickWandGenesis() | ||
− | + | mwand = NewMagickWand() | |
− | bo = MagickReadImage( | + | bo = MagickReadImage(mwand, fileimmagine) |
− | If bo = MagickFalse Then | + | If bo == MagickFalse Then |
− | Termina( | + | Termina(mwand) |
Error.Raise("Impossibile caricare l'immagine !") | Error.Raise("Impossibile caricare l'immagine !") | ||
Endif | Endif | ||
<FONT Color=gray>' ''Modifica l'immagine con l'effetto sfumato con vortice:''</font> | <FONT Color=gray>' ''Modifica l'immagine con l'effetto sfumato con vortice:''</font> | ||
− | MagickRadialBlurImage( | + | MagickRadialBlurImage(mwand, 50.0) |
− | bo = MagickWriteImages( | + | bo = MagickWriteImages(mwand, nuovofile, MagickTrue) |
− | If bo = MagickFalse Then | + | If bo == MagickFalse Then |
− | Termina( | + | Termina(mwand) |
Error.Raise("Impossibile creare il nuovo file dell'immagine sfumata !") | Error.Raise("Impossibile creare il nuovo file dell'immagine sfumata !") | ||
Endif | Endif | ||
− | Termina( | + | Termina(mwand) |
'''End''' | '''End''' | ||
− | '''Private''' Procedure Termina(mw As | + | '''Private''' Procedure Termina(mw As MagickWand) <FONT Color=gray>' ''Libera la memoria e termina il programma''</font> |
DestroyMagickWand(mw) | DestroyMagickWand(mw) |
Versione attuale delle 06:03, 20 nov 2022
Il sistema ImageMagick consente di creare, modificare e convertire immagini bitmap. Può altresì leggere e scrivere immagini di oltre 200 formati.
Per poter fruire in Gambas delle risorse, è necessario avere installata nel sistema e richiamare la seguente libreria condivisa: "libMagickWand-6.Q16.so.6.0.0 ".
Le risorse di questa libreria ci consentono - fra l'altro - di sfumare un'immagine con un effetto vortice.
Mostriamo un esempio pratico:
Library "libMagickWand-6.Q16:6.0.0" Private Const MagickPathExtent As Integer = 4096 Public Struct MagickWand id As Long name[MagickPathExtent] As Byte images As Pointer image_info As Pointer exception As Pointer insert_before As Integer image_pending As Integer debug_ As Integer signature As Long End Struct Private Enum MagickFalse = 0, MagickTrue ' void MagickWandGenesis(void) ' Initializes the MagickWand environment. Private Extern MagickWandGenesis() ' MagickWand *NewMagickWand(void) ' Returns a wand required for all other methods in the API. Private Extern NewMagickWand() As MagickWand ' MagickBooleanType MagickReadImage(MagickWand *wand,const char *filename) ' Reads an image or image sequence. Private Extern MagickReadImage(wand As MagickWand, filename As String) As Integer ' MagickBooleanType MagickRadialBlurImage(MagickWand *wand, const double angle) ' Blurs an image. Private Extern MagickRadialBlurImage(wand As MagickWand, blur As Float) As Integer ' MagickBooleanType MagickWriteImages(MagickWand *wand, const char *filename,const MagickBooleanType adjoin) ' Writes an image or image sequence. Private Extern MagickWriteImages(wand As MagickWand, filename As String, adjoin As Boolean) As Integer ' MagickWand *DestroyMagickWand(MagickWand *wand) ' Deallocates memory associated with an MagickWand. Private Extern DestroyMagickWand(wand As MagickWand) As MagickWand ' void MagickWandTerminus(void) ' Terminates the MagickWand environment. Private Extern MagickWandTerminus() Public Sub Main() Dim bo As Integer Dim mwand As MagickWand Dim fileimmagine, nuovofile As String fileimmagine = "/percorso/del/file/immagine" nuovofile = "/percorso/del/nuovo/file/dell'immagine/spostata" MagickWandGenesis() mwand = NewMagickWand() bo = MagickReadImage(mwand, fileimmagine) If bo == MagickFalse Then Termina(mwand) Error.Raise("Impossibile caricare l'immagine !") Endif ' Modifica l'immagine con l'effetto sfumato con vortice: MagickRadialBlurImage(mwand, 50.0) bo = MagickWriteImages(mwand, nuovofile, MagickTrue) If bo == MagickFalse Then Termina(mwand) Error.Raise("Impossibile creare il nuovo file dell'immagine sfumata !") Endif Termina(mwand) End Private Procedure Termina(mw As MagickWand) ' Libera la memoria e termina il programma DestroyMagickWand(mw) Wait 0.01 MagickWandTerminus() End