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.
 
(3 versioni intermedie di uno stesso utente non sono mostrate)
Riga 1: Riga 1:
 
Il sistema ''ImageMagick'' consente di creare, modificare e convertire immagini bitmap. Può altresì leggere e scrivere immagini di oltre 200 formati.
 
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.2.0.0'' " (o altra versione).
+
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":
 
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":
Riga 9: Riga 8:
 
  [  A]
 
  [  A]
 
Mostriamo un esempio pratico:
 
Mostriamo un esempio pratico:
  Library "libMagickWand-6.Q16:2.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 32:
 
  <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 Pointer
+
  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 Pointer, filename As String) As Boolean
+
  Private Extern MagickReadImage(wand As MagickWand, filename As String) As Integer
 
   
 
   
 
  <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 Pointer, x As Long, y As Long) As Boolean
+
  Private Extern MagickRollImage(wand As MagickWand, x As Long, y As Long) 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 Pointer, filename As String, adjoin As Boolean) As Boolean
+
  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 Pointer) As Pointer
+
  Private Extern DestroyMagickWand(wand As MagickWand) As MagickWand
 
   
 
   
 
  <FONT Color=gray>' ''void MagickWandTerminus(void)''
 
  <FONT Color=gray>' ''void MagickWandTerminus(void)''
Riga 44: Riga 57:
 
  '''Public''' Sub Main()
 
  '''Public''' Sub Main()
 
    
 
    
   Dim bo As Boolean
+
   Dim bo As Integer
   Dim magickwand As Pointer
+
   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/file/immagine/ridimensionata''</font>"
 
+
 
  MagickWandGenesis()
+
  MagickWandGenesis()
     
 
  magickwand = NewMagickWand()
 
 
 
  bo = MagickReadImage(magickwand, fileimmagine)
 
  If bo = MagickFalse Then
 
    Termina(magickwand, pw)
 
    Error.Raise("Impossibile caricare l'immagine !")
 
  Endif
 
 
    
 
    
 +
  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(magickwand, 120, 0)
+
  MagickRollImage(mwand, 120, 0)
 
+
  bo = MagickWriteImages(magickwand, nuovofile, MagickTrue)
+
  bo = MagickWriteImages(mwand, nuovofile, MagickTrue)
  If bo = MagickFalse Then
+
  If bo = MagickFalse Then
    Termina(magickwand, pw)
+
    Error.Raise("Impossibile creare il nuovo file dell'immagine ridimensionata !")
    Error.Raise("Impossibile creare il nuovo file dell'immagine spostata !")
+
    Chiude(mwand)
  Endif
+
  Endif
 
+
  Termina(magickwand, pw)
+
  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()
 
    
 
    
 
'''Private''' Procedure Termina(mw As Pointer)    <FONT Color=gray>' ''Libera la memoria e termina il programma''</font>
 
 
 
  DestroyMagickWand(mw)
 
  Wait 0.01
 
  MagickWandTerminus()
 
 
 
 
  '''End'''
 
  '''End'''
 
  
  

Versione attuale delle 18:43, 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 Integer

' 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 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/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


Riferimenti