Differenze tra le versioni di "Spostare il contenuto all'interno di un'immagine mediante le funzioni esterne del API di ImageMagick"
Da Gambas-it.org - Wikipedia.
Riga 10: | Riga 10: | ||
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 19: | Riga 33: | ||
<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 Boolean |
<FONT Color=gray>' ''MagickBooleanType MagickRollImage(MagickWand *wand,const ssize_t x, const size_t y)'' | <FONT Color=gray>' ''MagickBooleanType MagickRollImage(MagickWand *wand,const ssize_t x, const size_t y)'' | ||
' ''Offsets an image as defined by x_offset and y_offset.''</font> | ' ''Offsets an image as defined by x_offset and y_offset.''</font> | ||
− | Private Extern MagickRollImage(wand As | + | Private Extern MagickRollImage(wand As MagickWand, x As Long, y As Long) As Boolean |
− | + | ||
<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 Boolean |
− | + | ||
<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 Pointer |
<FONT Color=gray>' ''void MagickWandTerminus(void)'' | <FONT Color=gray>' ''void MagickWandTerminus(void)'' | ||
Riga 44: | Riga 58: | ||
'''Public''' Sub Main() | '''Public''' Sub Main() | ||
− | + | Dim bo As Boolean | |
− | + | Dim mwand As MagickWand | |
− | + | Dim fileimmagine, nuovofile As String | |
− | + | ||
− | + | fileimmagine = "<FONT Color=gray>''/percorso/del/file/immagine''</font>" | |
− | + | nuovofile = "<FONT Color=gray>''/percorso/del/file/immagine/ridimensionata''</font>" | |
− | + | ||
− | + | MagickWandGenesis() | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
+ | mwand = NewMagickWand() | ||
+ | |||
+ | bo = MagickReadImage(mwand, fileimmagine) | ||
+ | If bo = MagickFalse Then | ||
+ | Error.Raise("Impossibile caricare il file immagine !") | ||
+ | Chiude(mwand) | ||
+ | Endif | ||
+ | |||
<FONT Color=gray>' ''Sposta tutto il disegno all'interno dell'immagine lungo il solo asse di spostamento x:''</font> | <FONT Color=gray>' ''Sposta tutto il disegno all'interno dell'immagine lungo il solo asse di spostamento x:''</font> | ||
− | + | MagickRollImage(mwand, 120, 0) | |
− | + | ||
− | + | bo = MagickWriteImages(mwand, nuovofile, MagickTrue) | |
− | + | If bo = MagickFalse Then | |
− | + | Error.Raise("Impossibile creare il nuovo file dell'immagine ridimensionata !") | |
− | + | Chiude(mwand) | |
− | + | Endif | |
− | + | ||
− | + | Chiude(mwand) | |
'''End''' | '''End''' | ||
+ | |||
+ | '''Private''' Procedure Chiude(mw As MagickWand) | ||
+ | |||
+ | <FONT Color=gray>' ''Libera la memoria e chiude la libreria "ImageMagick":''</font> | ||
+ | DestroyMagickWand(mw) | ||
+ | Wait 0.01 | ||
+ | MagickWandTerminus() | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
'''End''' | '''End''' | ||
Versione delle 16:34, 19 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 spostare il contenuto all'interno di un'immagine lungo uno o entrambi gli assi di spostamento x, y. Così, se l'immagine presenta, come disegno al suo interno, la lettera "A":
[ A ]
essa potrà essere spostata all'interno del campo dell'immagine medesima lungo il suo asse di spostamento x, ad esempio, così:
[ A]
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 Boolean ' MagickBooleanType MagickRollImage(MagickWand *wand,const ssize_t x, const size_t y) ' Offsets an image as defined by x_offset and y_offset. Private Extern MagickRollImage(wand As MagickWand, x As Long, y As Long) As Boolean ' 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 Boolean ' MagickWand *DestroyMagickWand(MagickWand *wand) ' Deallocates memory associated with an MagickWand. Private Extern DestroyMagickWand(wand As MagickWand) As Pointer ' void MagickWandTerminus(void) ' Terminates the MagickWand environment. Private Extern MagickWandTerminus() Public Sub Main() Dim bo As Boolean Dim mwand As MagickWand Dim fileimmagine, nuovofile As String fileimmagine = "/percorso/del/file/immagine" nuovofile = "/percorso/del/file/immagine/ridimensionata" MagickWandGenesis() mwand = NewMagickWand() bo = MagickReadImage(mwand, fileimmagine) If bo = MagickFalse Then Error.Raise("Impossibile caricare il file immagine !") Chiude(mwand) Endif ' Sposta tutto il disegno all'interno dell'immagine lungo il solo asse di spostamento x: MagickRollImage(mwand, 120, 0) bo = MagickWriteImages(mwand, nuovofile, MagickTrue) If bo = MagickFalse Then Error.Raise("Impossibile creare il nuovo file dell'immagine ridimensionata !") Chiude(mwand) Endif Chiude(mwand) End Private Procedure Chiude(mw As MagickWand) ' Libera la memoria e chiude la libreria "ImageMagick": DestroyMagickWand(mw) Wait 0.01 MagickWandTerminus() End