Differenze tra le versioni di "Modificare la risoluzione in PPI di un'immagine mediante le funzioni esterne del API di ImageMagick"
Da Gambas-it.org - Wikipedia.
(Creata pagina con "Il sistema <i>ImageMagick</i> consente di creare, modificare e convertire immagini bitmap. Può altresì leggere e scrivere immagini di oltre 200 formati. Per poter fruire in...") |
|||
Riga 1: | Riga 1: | ||
Il sistema <i>ImageMagick</i> consente di creare, modificare e convertire immagini bitmap. Può altresì leggere e scrivere immagini di oltre 200 formati. | Il sistema <i>ImageMagick</i> 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: "<i>libMagickWand- | + | Per poter fruire in Gambas delle risorse, è necessario avere installata nel sistema e richiamare la seguente libreria condivisa: "<i>libMagickWand-7.Q16HDRI.so.10.0.1</i> ". |
Mostriamo di seguito un semplice esempio pratico per modificare la risoluzione in PPI (<i>Pixel Per Inches</i> ) di un'immagine. | Mostriamo di seguito un semplice esempio pratico per modificare la risoluzione in PPI (<i>Pixel Per Inches</i> ) di un'immagine. | ||
− | <pre>Library "libMagickWand- | + | <pre>Library "libMagickWand-7.Q16HDRI:10.0.1" |
Private Const MagickPathExtent As Integer = 4096 | Private Const MagickPathExtent As Integer = 4096 | ||
Riga 56: | Riga 56: | ||
− | + | Public Sub Main() | |
Dim bo As Integer | Dim bo As Integer | ||
Riga 62: | Riga 62: | ||
Dim fileimmagine, nuovofile As String | Dim fileimmagine, nuovofile As String | ||
− | fileimmagine = "<font color= | + | fileimmagine = "<font color=darkgreen><i>/percorso/del/file/immagine</i></font>" |
− | nuovofile = "<font color= | + | nuovofile = "<font color=darkgreen><i>/percorso/del/nuovo/file/immagine</i></font>" |
MagickWandGenesis() | MagickWandGenesis() | ||
Riga 89: | Riga 89: | ||
Chiude(mw) | Chiude(mw) | ||
− | + | End | |
− | + | ||
− | + | ||
+ | Private Procedure Chiude(mgw As MagickWand) | ||
<font color="gray">' <i>Libera la memoria e chiude la libreria "ImageMagick":</i></font> | <font color="gray">' <i>Libera la memoria e chiude la libreria "ImageMagick":</i></font> | ||
Riga 97: | Riga 98: | ||
Wait 0.01 | Wait 0.01 | ||
MagickWandTerminus() | MagickWandTerminus() | ||
− | + | ||
− | + | End |
Versione attuale delle 04:04, 6 giu 2024
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-7.Q16HDRI.so.10.0.1 ".
Mostriamo di seguito un semplice esempio pratico per modificare la risoluzione in PPI (Pixel Per Inches ) di un'immagine.
Library "libMagickWand-7.Q16HDRI:10.0.1" 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 UndefinedResolution = 0, PixelsPerInchResolution, PixelsPerCentimeterResolution 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 MagickSetImageResolution(MagickWand *wand, const double x_resolution, const double y_resolution) ' Sets the image resolution. Private Extern MagickSetImageResolution(wand As MagickWand, x_resolution As Float, y_resolution As Float) As Integer ' MagickBooleanType MagickSetImageUnits(MagickWand *wand, const ResolutionType units) ' Sets the image units of resolution. Private Extern MagickSetImageUnits(wand As MagickWand, units As Integer) 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 mw As MagickWand Dim fileimmagine, nuovofile As String fileimmagine = "/percorso/del/file/immagine" nuovofile = "/percorso/del/nuovo/file/immagine" MagickWandGenesis() mw = NewMagickWand() bo = MagickReadImage(mw, fileimmagine) If bo = MagickFalse Then Error.Raise("Impossibile caricare il file immagine !") Chiude(mw) Endif ' Imposta la risoluzione ("Pixel Per Inches") dell'immagine: MagickSetImageResolution(mw, 150.0, 150.0) ' Modifica la risoluzione ("Pixel Per Inches") dell'immagine: MagickSetImageUnits(mw, PixelsPerInchResolution) bo = MagickWriteImages(mw, nuovofile, MagickTrue) If bo = MagickFalse Then Error.Raise("Impossibile creare il nuovo file dell'immagine ridimensionata !") Chiude(mw) Endif Chiude(mw) End Private Procedure Chiude(mgw As MagickWand) ' Libera la memoria e chiude la libreria "ImageMagick": DestroyMagickWand(mgw) Wait 0.01 MagickWandTerminus() End