Differenze tra le versioni di "Inserire un'immagine all'interno di un'altra immagine mediante le funzioni esterne del API di Libgdk pixbuf"

Da Gambas-it.org - Wikipedia.
 
(4 versioni intermedie di uno stesso utente non sono mostrate)
Riga 11: Riga 11:
 
* il 8° parametro formale "''double offset_y''"  è un tipo corrispondente al ''Float'' di Gambas, che rappresenta l'eventuale valore (positivo, uguale a zero o negativo) di spostamento in verticale rispetto al valore precedentemente impostato nel 3° parametro formale.
 
* il 8° parametro formale "''double offset_y''"  è un tipo corrispondente al ''Float'' di Gambas, che rappresenta l'eventuale valore (positivo, uguale a zero o negativo) di spostamento in verticale rispetto al valore precedentemente impostato nel 3° parametro formale.
  
E' necessario avere installata e richiamare in Gambas la libreria dinamica condivisa: "''libgdk pixbuf-2.0''"
+
E' necessario avere installata e richiamare in Gambas la libreria dinamica condivisa: "''libgdk pixbuf-2.0.so.0.4200.8'' ".
  
  
 
Mostriamo un semplice esempio pratico:
 
Mostriamo un semplice esempio pratico:
  Library "libgdk_pixbuf-2.0"
+
  Library "libgdk_pixbuf-2.0:0.4200.8"
 
+
' Questa enumerazione descrive le diverse modalità di interpolazione che possono essere utilizzate con le funzioni di ridimensionamento.
+
<FONT Color=gray>' ''Questa enumerazione descrive le diverse modalità di interpolazione che possono essere utilizzate con le funzioni di ridimensionamento.''</font>
Private Enum GDK_INTERP_NEAREST = 0, GDK_INTERP_TILES, GDK_INTERP_BILINEAR, GDK_INTERP_HYPER
+
Private Enum GDK_INTERP_NEAREST = 0, GDK_INTERP_TILES, GDK_INTERP_BILINEAR, GDK_INTERP_HYPER
 
+
Private Const GDK_COLORSPACE_RGB As Integer = 0
+
Private Const GDK_COLORSPACE_RGB As Integer = 0
 
+
' GdkPixbuf * gdk_pixbuf_new_from_file (const char *filename, GError **error)
+
<FONT Color=gray>' ''GdkPixbuf * gdk_pixbuf_new_from_file (const char *filename, GError **error)''
' Creates a new pixbuf by loading an image from a file.
+
' ''Creates a new pixbuf by loading an image from a file.''</font>
Private Extern gdk_pixbuf_new_from_file(filename As String, gerro As Pointer) As Pointer
+
Private Extern gdk_pixbuf_new_from_file(filename As String, gerro As Pointer) As Pointer
 
+
' int gdk_pixbuf_get_width (const GdkPixbuf *pixbuf)
+
<FONT Color=gray>' ''int gdk_pixbuf_get_width (const GdkPixbuf *pixbuf)''
' Queries the width of a pixbuf.
+
' ''Queries the width of a pixbuf.''</font>
Private Extern gdk_pixbuf_get_width(pixbuf As Pointer) As Integer
+
Private Extern gdk_pixbuf_get_width(pixbuf As Pointer) As Integer
 
+
' int gdk_pixbuf_get_height (const GdkPixbuf *pixbuf)
+
<FONT Color=gray>' ''int gdk_pixbuf_get_height (const GdkPixbuf *pixbuf)''
' Queries the height of a pixbuf.
+
' ''Queries the height of a pixbuf.''</font>
Private Extern gdk_pixbuf_get_height(pixbuf As Pointer) As Integer
+
Private Extern gdk_pixbuf_get_height(pixbuf As Pointer) As Integer
 
+
' void gdk_pixbuf_composite (const GdkPixbuf *src, GdkPixbuf *dest, int dest_x, int dest_y, int dest_width, int dest_height,
+
<FONT Color=gray>' ''void gdk_pixbuf_composite (const GdkPixbuf *src, GdkPixbuf *dest, int dest_x, int dest_y, int dest_width, int dest_height,''
'                       double offset_x, double offset_y, double scale_x, double scale_y, GdkInterpType interp_type, int overall_alpha)
+
'                            ''double offset_x, double offset_y, double scale_x, double scale_y, GdkInterpType interp_type, int overall_alpha)''
' Creates a transformation of the source image src by scaling by scale_x and scale_y then translating by offset_x and offset_y.
+
' ''Creates a transformation of the source image src by scaling by scale_x and scale_y then translating by offset_x and offset_y.''</font>
Private Extern gdk_pixbuf_composite(src As Pointer, dest As Pointer, dest_x As Integer, dest_y As Integer, dest_width As Integer, dest_height As Integer, offset_x As Float, offset_y As Float, scale_x As Float, scale_y As Float, interp_type As Integer, overall_alpha As Integer)
+
<FONT size=1>Private Extern gdk_pixbuf_composite(src As Pointer, dest As Pointer, dest_x As Integer, dest_y As Integer, dest_width As Integer, dest_height As Integer, offset_x As Float, offset_y As Float, scale_x As Float, scale_y As Float, interp_type As Integer, overall_alpha As Integer)</font>
 
+
' gboolean gdk_pixbuf_save (GdkPixbuf *pixbuf, const char *filename, const char *type, GError **error, ...)
+
<FONT Color=gray>' ''gboolean gdk_pixbuf_save (GdkPixbuf *pixbuf, const char *filename, const char *type, GError **error, ...)
' Saves pixbuf to a file in format type.
+
' ''Saves pixbuf to a file in format type.''</font>
Private Extern gdk_pixbuf_save(pixbuf As Pointer, filename As String, type As String, gerror As Pointer, ptr As Pointer) As Boolean
+
Private Extern gdk_pixbuf_save(pixbuf As Pointer, filename As String, type As String, gerror As Pointer, ptr As Pointer) As Boolean
 
+
' void g_object_unref (gpointer object)
+
<FONT Color=gray>' ''void g_object_unref (gpointer object)''
' Decreases the reference count of object.
+
' ''Decreases the reference count of object.''</font>
Private Extern g_object_unref(gobject As Pointer)
+
Private Extern g_object_unref(gobject As Pointer)
 
+
 
+
Public Sub Main()
+
'''Public''' Sub Main()
 
+
 
 
   Dim pb1, pb2 As Pointer
 
   Dim pb1, pb2 As Pointer
 
   Dim im1, im2 As String
 
   Dim im1, im2 As String
 
   Dim w, h As Integer
 
   Dim w, h As Integer
 
   Dim bo As Boolean
 
   Dim bo As Boolean
 +
 
 +
  im1 = "<FONT Color=gray>''/percorso/del/file/immagine/nella/quale/sarà/copiata/un'altra/immagine/(o parte di essa)''</font>"
 
    
 
    
  im1 = "/home/ploppo/Scrivania/IMMAGINI/luna.jpg"
+
   pb1 = gdk_pixbuf_new_from_file(im1, 0)
    
+
  If pb1 == 0 Then Error.Raise("ERRORE !")
  pb1 = gdk_pixbuf_new_from_file(im1, 0)
+
 
  If pb1 = 0 Then Error.Raise("ERRORE !")
+
  w = gdk_pixbuf_get_width(pb1)
 +
  h = gdk_pixbuf_get_height(pb1)
 +
 
 +
  Print "Immagine destinazione: "; im1
 +
  Print "Dimensioni:            "; w; "x"; h; " pixel\n"
 
    
 
    
  w = gdk_pixbuf_get_width(pb1)
+
  im2 = "<FONT Color=gray>''/percorso/del/file/della/immagine/(o parte di essa)/che/sarà/copiata/in/un'altra/immagine''</font>"
  h = gdk_pixbuf_get_height(pb1)
+
  pb2 = gdk_pixbuf_new_from_file(im2, 0)
 +
  If pb2 == 0 Then Error.Raise("ERRORE !")
 
    
 
    
  Print "Immagine destinazione: "; im1
+
  w = gdk_pixbuf_get_width(pb2)
  Print "Dimensioni:            "; w; "x"; h; " pixel\n"
+
  h = gdk_pixbuf_get_height(pb2)
 
    
 
    
  im2 = "/home/ploppo/Scrivania/IMMAGINI/Ultima-cena.jpg"
+
  Print "Immagine da copiare:  "; im2
  pb2 = gdk_pixbuf_new_from_file(im2, 0)
+
  Print "Dimensioni:            "; w; "x"; h; " pixel"
  If pb2 = 0 Then Error.Raise("ERRORE !")
 
 
    
 
    
  w = gdk_pixbuf_get_width(pb2)
+
  <FONT Color=#B22222>gdk_pixbuf_composite</font>(pb2, pb1, 300, 300, 300, 150, 200, -200, 1, 1, GDK_INTERP_HYPER, 255)
  h = gdk_pixbuf_get_height(pb2)
 
 
    
 
    
  Print "Immagine da copiare:   "; im2
+
   bo = gdk_pixbuf_save(pb1, "/tmp/test.png", "png", 0, 0)
  Print "Dimensioni:            "; w; "x"; h; " pixel"
+
  If bo == False Then Error.Raise("ERRORE !")
 
    
 
    
'
+
  g_object_unref(pb2)
  gdk_pixbuf_composite(pb2, pb1, 300, 300, 300, 150, 200, -200, 1, 1, GDK_INTERP_HYPER, 255)
+
  g_object_unref(pb1)
 
    
 
    
  bo = gdk_pixbuf_save(pb1, "/tmp/test.png", "png", 0, 0)
+
'''End'''
  If bo = False Then Error.Raise("ERRORE !")
 
 
 
  g_object_unref(pb2)
 
  g_object_unref(pb1)
 
 
 
End
 
 
 
 
 
 
 
 
 
  
  
Riga 96: Riga 91:
 
* https://developer.gnome.org/gdk-pixbuf/stable/gdk-pixbuf-Scaling.html#gdk-pixbuf-composite
 
* https://developer.gnome.org/gdk-pixbuf/stable/gdk-pixbuf-Scaling.html#gdk-pixbuf-composite
 
* http://www.crategus.com/books/cl-cffi-gtk/pages/gdk-pixbuf_fun_gdk-pixbuf-composite.html
 
* http://www.crategus.com/books/cl-cffi-gtk/pages/gdk-pixbuf_fun_gdk-pixbuf-composite.html
 
 
 
 
<FONT Color=red size=4><B>Pagina in costruzione !</b></font>
 

Versione attuale delle 15:28, 1 mag 2023

La funzione esterna "gdk_pixbuf_composite( )" del API di gdk pixbuf consente di inserire un'immagine o parte di essa all'interno di un'altra immagine.

In particolare i parametri della predetta funzione esterna "gdk_pixbuf_composite( )" dovranno essere così gestiti:

  • il 1° parametro formale "const GdkPixbuf *src" è un Puntatore all'oggetto Gdkpixbuf, che rappresenta l'immagine da copiare;
  • il 2° parametro formale "GdkPixbuf *dest" è un Puntatore all'oggetto Gdkpixbuf, che rappresenta l'immagine all'interno della quale sarà copiata l'immagine puntata dal 1° parametro formale;
  • il 3° parametro formale "int dest_x" è un intero, che rappresenta il punto x sia dell'immagine (o della sua parte) da copiare, sia dell'immagine ospitante ed in particoalre il punto ove sarà copiata l'immagine (o sua parte);
  • il 4° parametro formale "int dest_y" è un intero, che rappresenta il punto y sia dell'immagine (o della sua parte) da copiare, sia dell'immagine ospitante ed in particoalre il punto ove sarà copiata l'immagine (o sua parte);
  • il 5° parametro formale "int dest_width" è un intero, che rappresenta la larghezza in pixel dell'area dell'immagine da copiare;
  • il 6° parametro formale "int dest_height" è un intero, che rappresenta l'altezza in pixel dell'area dell'immagine da copiare;
  • il 7° parametro formale "double offset_x" è un tipo corrispondente al Float di Gambas, che rappresenta l'eventuale valore (positivo, uguale a zero o negativo) di spostamento in orizzontale rispetto al valore precedentemente impostato nel 3° parametro formale;
  • il 8° parametro formale "double offset_y" è un tipo corrispondente al Float di Gambas, che rappresenta l'eventuale valore (positivo, uguale a zero o negativo) di spostamento in verticale rispetto al valore precedentemente impostato nel 3° parametro formale.

E' necessario avere installata e richiamare in Gambas la libreria dinamica condivisa: "libgdk pixbuf-2.0.so.0.4200.8 ".


Mostriamo un semplice esempio pratico:

Library "libgdk_pixbuf-2.0:0.4200.8"

' Questa enumerazione descrive le diverse modalità di interpolazione che possono essere utilizzate con le funzioni di ridimensionamento.
Private Enum GDK_INTERP_NEAREST = 0, GDK_INTERP_TILES, GDK_INTERP_BILINEAR, GDK_INTERP_HYPER

Private Const GDK_COLORSPACE_RGB As Integer = 0

' GdkPixbuf * gdk_pixbuf_new_from_file (const char *filename, GError **error)
' Creates a new pixbuf by loading an image from a file.
Private Extern gdk_pixbuf_new_from_file(filename As String, gerro As Pointer) As Pointer

' int gdk_pixbuf_get_width (const GdkPixbuf *pixbuf)
' Queries the width of a pixbuf.
Private Extern gdk_pixbuf_get_width(pixbuf As Pointer) As Integer

' int gdk_pixbuf_get_height (const GdkPixbuf *pixbuf)
' Queries the height of a pixbuf.
Private Extern gdk_pixbuf_get_height(pixbuf As Pointer) As Integer

' void gdk_pixbuf_composite (const GdkPixbuf *src, GdkPixbuf *dest, int dest_x, int dest_y, int dest_width, int dest_height,
'                            double offset_x, double offset_y, double scale_x, double scale_y, GdkInterpType interp_type, int overall_alpha)
' Creates a transformation of the source image src by scaling by scale_x and scale_y then translating by offset_x and offset_y.
Private Extern gdk_pixbuf_composite(src As Pointer, dest As Pointer, dest_x As Integer, dest_y As Integer, dest_width As Integer, dest_height As Integer, offset_x As Float, offset_y As Float, scale_x As Float, scale_y As Float, interp_type As Integer, overall_alpha As Integer)

' gboolean gdk_pixbuf_save (GdkPixbuf *pixbuf, const char *filename, const char *type, GError **error, ...)
' Saves pixbuf to a file in format type.
Private Extern gdk_pixbuf_save(pixbuf As Pointer, filename As String, type As String, gerror As Pointer, ptr As Pointer) As Boolean

' void g_object_unref (gpointer object)
' Decreases the reference count of object.
Private Extern g_object_unref(gobject As Pointer)


Public Sub Main()
 
 Dim pb1, pb2 As Pointer
 Dim im1, im2 As String
 Dim w, h As Integer
 Dim bo As Boolean
  
 im1 = "/percorso/del/file/immagine/nella/quale/sarà/copiata/un'altra/immagine/(o parte di essa)"
 
 pb1 = gdk_pixbuf_new_from_file(im1, 0)
 If pb1 == 0 Then Error.Raise("ERRORE !")
  
 w = gdk_pixbuf_get_width(pb1)
 h = gdk_pixbuf_get_height(pb1)
  
 Print "Immagine destinazione: "; im1
 Print "Dimensioni:            "; w; "x"; h; " pixel\n"
  
 im2 = "/percorso/del/file/della/immagine/(o parte di essa)/che/sarà/copiata/in/un'altra/immagine"
 pb2 = gdk_pixbuf_new_from_file(im2, 0)
 If pb2 == 0 Then Error.Raise("ERRORE !")
  
 w = gdk_pixbuf_get_width(pb2)
 h = gdk_pixbuf_get_height(pb2)
  
 Print "Immagine da copiare:   "; im2
 Print "Dimensioni:            "; w; "x"; h; " pixel"
  
 gdk_pixbuf_composite(pb2, pb1, 300, 300, 300, 150, 200, -200, 1, 1, GDK_INTERP_HYPER, 255)
  
 bo = gdk_pixbuf_save(pb1, "/tmp/test.png", "png", 0, 0)
 If bo == False Then Error.Raise("ERRORE !")
  
 g_object_unref(pb2)
 g_object_unref(pb1)
  
End


Riferimenti