Differenze tra le versioni di "Ruotare 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'' ". | ||
− | |||
Mostriamo di seguito un semplice esempio pratico per ruotare un'immagine: | Mostriamo di seguito un semplice esempio pratico per ruotare un'immagine: | ||
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 15: | Riga 28: | ||
<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>' ''PixelWand *NewPixelWand(void)'' | <FONT Color=gray>' ''PixelWand *NewPixelWand(void)'' | ||
' ''Returns a new pixel wand.''</font> | ' ''Returns a new pixel wand.''</font> | ||
− | Private Extern NewPixelWand() As | + | Private Extern NewPixelWand() As Pointer |
<FONT Color=gray>' ''void PixelSetRed(PixelWand *wand, const double red)'' | <FONT Color=gray>' ''void PixelSetRed(PixelWand *wand, const double red)'' | ||
' ''Sets the normalized red color of the pixel wand.''</font> | ' ''Sets the normalized red color of the pixel wand.''</font> | ||
− | Private Extern PixelSetRed(Pwand As | + | Private Extern PixelSetRed(Pwand As Pointer, red As Float) |
<FONT Color=gray>' ''void PixelSetGreen(PixelWand *wand, const double green)'' | <FONT Color=gray>' ''void PixelSetGreen(PixelWand *wand, const double green)'' | ||
' ''Sets the normalized green color of the pixel wand.''</font> | ' ''Sets the normalized green color of the pixel wand.''</font> | ||
− | Private Extern PixelSetGreen(Pwand As | + | Private Extern PixelSetGreen(Pwand As Pointer, green As Float) |
<FONT Color=gray>' ''void PixelSetBlue(PixelWand *wand, const double blue)'' | <FONT Color=gray>' ''void PixelSetBlue(PixelWand *wand, const double blue)'' | ||
' ''Sets the normalized blue color of the pixel wand.''</font> | ' ''Sets the normalized blue color of the pixel wand.''</font> | ||
− | Private Extern PixelSetBlue(Pwand As | + | Private Extern PixelSetBlue(Pwand As Pointer, blue As Float) |
<FONT Color=gray>' ''void PixelSetAlpha(PixelWand *wand, const double alpha)'' | <FONT Color=gray>' ''void PixelSetAlpha(PixelWand *wand, const double alpha)'' | ||
' ''Sets the normalized alpha color of the pixel wand.''</font> | ' ''Sets the normalized alpha color of the pixel wand.''</font> | ||
− | Private Extern PixelSetAlpha(Pwand As | + | Private Extern PixelSetAlpha(Pwand As Pointer, alpha As Float) |
<FONT Color=gray>' ''MagickBooleanType MagickRotateImage(MagickWand *wand, const PixelWand *background,const double degrees)'' | <FONT Color=gray>' ''MagickBooleanType MagickRotateImage(MagickWand *wand, const PixelWand *background,const double degrees)'' | ||
' ''Rotates an image the specified number of degrees.''</font> | ' ''Rotates an image the specified number of degrees.''</font> | ||
− | Private Extern MagickRotateImage(wand As | + | Private Extern MagickRotateImage(wand As MagickWand, background As Pointer, degrees 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>' ''PixelWand *DestroyPixelWand(PixelWand *wand)'' | <FONT Color=gray>' ''PixelWand *DestroyPixelWand(PixelWand *wand)'' | ||
' ''Deallocates resources associated with a PixelWand.''</font> | ' ''Deallocates resources associated with a PixelWand.''</font> | ||
− | Private Extern DestroyPixelWand(Pwand As | + | Private Extern DestroyPixelWand(Pwand As Pointer) As Pointer |
<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 64: | Riga 77: | ||
'''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 | ||
− | Dim pw As | + | Dim pw As Pointer |
fileimmagine = "<FONT Color=gray>''/percorso/del/file/immagine''</font>" | fileimmagine = "<FONT Color=gray>''/percorso/del/file/immagine''</font>" | ||
Riga 77: | Riga 90: | ||
pw = ColorFondo() | pw = ColorFondo() | ||
− | + | mwand = NewMagickWand() | |
− | bo = MagickReadImage( | + | bo = MagickReadImage(mwand, fileimmagine) |
If bo = MagickFalse Then | If bo = MagickFalse Then | ||
− | Termina( | + | Termina(mwand, pw) |
Error.Raise("Impossibile caricare l'immagine !") | Error.Raise("Impossibile caricare l'immagine !") | ||
Endif | Endif | ||
<FONT Color=gray>' ''Ruota l'immegine di 135,00° a destra:''</font> | <FONT Color=gray>' ''Ruota l'immegine di 135,00° a destra:''</font> | ||
− | MagickRotateImage( | + | MagickRotateImage(mwand, pw, 135.00) |
− | bo = MagickWriteImages( | + | bo = MagickWriteImages(mwand, nuovofile, MagickTrue) |
If bo = MagickFalse Then | If bo = MagickFalse Then | ||
− | Termina( | + | Termina(mwand, pw) |
Error.Raise("Impossibile creare il nuovo file dell'immagine ruotata !") | Error.Raise("Impossibile creare il nuovo file dell'immagine ruotata !") | ||
Endif | Endif | ||
− | Termina( | + | Termina(mwand, pw) |
'''End''' | '''End''' | ||
− | '''Private''' Function ColorFondo() As | + | '''Private''' Function ColorFondo() As Pointer |
− | Dim pxw As | + | Dim pxw As Pointer |
pxw = NewPixelWand() | pxw = NewPixelWand() | ||
Riga 113: | Riga 126: | ||
'''End''' | '''End''' | ||
− | '''Private''' Procedure Termina(mw As | + | '''Private''' Procedure Termina(mw As MagickWand, pixw As Pointer) <FONT Color=gray>' ''Libera la memoria e termina il programma''</font> |
DestroyPixelWand(pixw) | DestroyPixelWand(pixw) |
Versione attuale delle 02:25, 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 ".
Mostriamo di seguito un semplice esempio pratico per ruotare un'immagine:
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 ' PixelWand *NewPixelWand(void) ' Returns a new pixel wand. Private Extern NewPixelWand() As Pointer ' void PixelSetRed(PixelWand *wand, const double red) ' Sets the normalized red color of the pixel wand. Private Extern PixelSetRed(Pwand As Pointer, red As Float) ' void PixelSetGreen(PixelWand *wand, const double green) ' Sets the normalized green color of the pixel wand. Private Extern PixelSetGreen(Pwand As Pointer, green As Float) ' void PixelSetBlue(PixelWand *wand, const double blue) ' Sets the normalized blue color of the pixel wand. Private Extern PixelSetBlue(Pwand As Pointer, blue As Float) ' void PixelSetAlpha(PixelWand *wand, const double alpha) ' Sets the normalized alpha color of the pixel wand. Private Extern PixelSetAlpha(Pwand As Pointer, alpha As Float) ' MagickBooleanType MagickRotateImage(MagickWand *wand, const PixelWand *background,const double degrees) ' Rotates an image the specified number of degrees. Private Extern MagickRotateImage(wand As MagickWand, background As Pointer, degrees 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 ' PixelWand *DestroyPixelWand(PixelWand *wand) ' Deallocates resources associated with a PixelWand. Private Extern DestroyPixelWand(Pwand As Pointer) As Pointer ' 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 Dim pw As Pointer fileimmagine = "/percorso/del/file/immagine" nuovofile = "/percorso/del/nuovo/file/dell'immagine/ruotata" MagickWandGenesis() ' I triangoli lasciati vuoti dalla rotazione dell'immagine sono riempiti da un colore di fondo: pw = ColorFondo() mwand = NewMagickWand() bo = MagickReadImage(mwand, fileimmagine) If bo = MagickFalse Then Termina(mwand, pw) Error.Raise("Impossibile caricare l'immagine !") Endif ' Ruota l'immegine di 135,00° a destra: MagickRotateImage(mwand, pw, 135.00) bo = MagickWriteImages(mwand, nuovofile, MagickTrue) If bo = MagickFalse Then Termina(mwand, pw) Error.Raise("Impossibile creare il nuovo file dell'immagine ruotata !") Endif Termina(mwand, pw) End Private Function ColorFondo() As Pointer Dim pxw As Pointer pxw = NewPixelWand() PixelSetRed(pxw, 255.0) PixelSetGreen(pxw, 255.0) PixelSetBlue(pxw, 255.0) ' Imposta il canale Alfa a zero per la trasparenza: PixelSetAlpha(pxw, 0.0) Return pxw End Private Procedure Termina(mw As MagickWand, pixw As Pointer) ' Libera la memoria e termina il programma DestroyPixelWand(pixw) DestroyMagickWand(mw) Wait 0.01 MagickWandTerminus() End