Differenze tra le versioni di "Ottenere alcune informazioni sul file immagine con le funzioni del API di GTK+3 e GDK-PixBuf"

Da Gambas-it.org - Wikipedia.
 
(3 versioni intermedie di uno stesso utente non sono mostrate)
Riga 3: Riga 3:
 
Fra molteplici potenzialità esse consentono di ottenere alcune informazioni sui file immagine.
 
Fra molteplici potenzialità esse consentono di ottenere alcune informazioni sui file immagine.
  
Sarà necessario avere installata nel sistema la libreria: "''libgtk-3.so.0.2200.30''".
+
Sarà necessario avere installata nel sistema la libreria: "''libgdk_pixbuf-2.0.so.0.4200.8'' ".
 
 
 
 
  
 
Mostriamo un semplice esempio pratico:
 
Mostriamo un semplice esempio pratico:
 +
Library "libgdk_pixbuf-2.0:0.4200.8"
 +
 
  Public Struct GdkPixbufFormat
 
  Public Struct GdkPixbufFormat
 
   name As Pointer
 
   name As Pointer
Riga 19: Riga 19:
 
   license As Pointer
 
   license As Pointer
 
  End Struct
 
  End Struct
 
Library "libgtk-3:0.2200.30"
 
 
   
 
   
 
  <FONT Color=gray>' ''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)''
Riga 45: Riga 43:
 
  ' ''Queries whether a pixbuf has an alpha channel (opacity information).''</font>
 
  ' ''Queries whether a pixbuf has an alpha channel (opacity information).''</font>
 
  Private Extern gdk_pixbuf_get_has_alpha(GdkPixbuf As Pointer) As Boolean
 
  Private Extern gdk_pixbuf_get_has_alpha(GdkPixbuf As Pointer) As Boolean
 +
 +
<FONT Color=gray>' ''int gdk_pixbuf_get_bits_per_sample (const GdkPixbuf *pixbuf)''
 +
' ''Queries the number of bits per color sample in a pixbuf.''</font>
 +
Private Extern gdk_pixbuf_get_bits_per_sample(pixbuf As Pointer) As Integer
 +
 +
<FONT Color=gray>' ''int gdk_pixbuf_get_rowstride (const GdkPixbuf *pixbuf)''
 +
' ''Queries the rowstride of a pixbuf.''</font>
 +
Private Extern gdk_pixbuf_get_rowstride(pixbuf As Pointer) As Integer
 +
 +
<FONT Color=gray>' ''gsize gdk_pixbuf_get_byte_length (const GdkPixbuf *pixbuf)''
 +
' ''Returns the length of the pixel data, in bytes.''</font>
 +
Private Extern gdk_pixbuf_get_byte_length(pixbuf As Pointer) As Long
 
   
 
   
 
  <FONT Color=gray>' ''GdkPixbufFormat * gdk_pixbuf_get_file_info (const gchar *filename, gint *width, gint *height)''
 
  <FONT Color=gray>' ''GdkPixbufFormat * gdk_pixbuf_get_file_info (const gchar *filename, gint *width, gint *height)''
 
  ' ''Parses an image file far enough to determine its format and size.''</font>
 
  ' ''Parses an image file far enough to determine its format and size.''</font>
 
  Private Extern gdk_pixbuf_get_file_info(filename As String, width As Pointer, height As Pointer) As Pointer
 
  Private Extern gdk_pixbuf_get_file_info(filename As String, width As Pointer, height As Pointer) As Pointer
 +
 +
<FONT Color=gray>' ''void g_object_unref (gpointer object)''
 +
' ''Decreases the reference count of object.''</font>
 +
Private Extern g_object_unref(gobject As Pointer)
 
   
 
   
 
   
 
   
Riga 54: Riga 68:
 
   
 
   
 
   Dim nomefile As String = "<FONT Color=gray>''/percorso/del/file/immagine''</font>"
 
   Dim nomefile As String = "<FONT Color=gray>''/percorso/del/file/immagine''</font>"
   Dim w, wi, h, hi As Integer
+
   Dim i, wi, hi As Integer
   Dim Pixbuf As Pointer
+
   Dim l As Long
   Dim c As Byte
+
   Dim pixbuf As Pointer
 
   Dim bo As Boolean
 
   Dim bo As Boolean
 
   Dim PixbufFormat As New GdkPixbufFormat
 
   Dim PixbufFormat As New GdkPixbufFormat
 
   
 
   
   Pixbuf = gdk_pixbuf_new_from_file(nomefile, 0)
+
   pixbuf = gdk_pixbuf_new_from_file(nomefile, 0)
 +
  If pixbuf == 0 Then Error.Raise("Errore !")
 +
 
 +
  Print "File immagine:            "; nomefile
 +
  i = gdk_pixbuf_get_width(pixbuf)
 +
  Print "Larghezza:                "; i; " pixel"
 +
  i = gdk_pixbuf_get_height(pixbuf)
 +
  Print "Altezza:                  "; i; " pixel"
 +
  i = gdk_pixbuf_get_rowstride(pixbuf)
 +
  Print "Numero di byte per riga:  "; i
 +
  i = gdk_pixbuf_get_n_channels(pixbuf)
 +
  Print "Canali:                  "; i
 +
  bo = gdk_pixbuf_get_has_alpha(pixbuf)
 +
  Print "Canale Alfa:              "; bo
 +
  i = gdk_pixbuf_get_bits_per_sample(pixbuf)
 +
  Print "Risoluzione:              "; i; " bit"
 +
  l = gdk_pixbuf_get_byte_length(pixbuf)
 +
  Print "Lunghezza dei dati pixel: "; l; " byte"
 
    
 
    
   w = gdk_pixbuf_get_width(Pixbuf)
+
   g_object_unref(pixbuf)
  Print "Larghezza:  "; w; " pixel"
 
  h = gdk_pixbuf_get_height(Pixbuf)
 
  Print "Altezza:    "; h; " pixel"
 
  c = gdk_pixbuf_get_n_channels(Pixbuf)
 
  Print "Canali:      "; c
 
  bo = gdk_pixbuf_get_has_alpha(Pixbuf)
 
  Print "Canale Alfa: "; bo
 
 
    
 
    
 
  <FONT Color=gray>''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''</font>
 
  <FONT Color=gray>''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''</font>
Riga 76: Riga 100:
 
    
 
    
 
   With PixbufFormat
 
   With PixbufFormat
     Print "Name:        "; String@(.name)                  <FONT Color=gray>' ''Il nome del formato immagine''</font>
+
     Print "\nName:        "; String@(.name)                  <FONT Color=gray>' ''Il nome del formato immagine''</font>
 
     Print "Domain:      "; String@(.domain)                <FONT Color=gray>' ''Il contrassegno del modulo''</font>
 
     Print "Domain:      "; String@(.domain)                <FONT Color=gray>' ''Il contrassegno del modulo''</font>
 
     Print "Description: "; String@(.description)          <FONT Color=gray>' ''Il dominio del messaggio per la descrizione''</font>
 
     Print "Description: "; String@(.description)          <FONT Color=gray>' ''Il dominio del messaggio per la descrizione''</font>

Versione attuale delle 15:54, 3 mag 2023

GTK+3 è una libreria per la creazione di interfacce grafiche utente. GDK-PixBuf è una libreria grafica per il caricamento e la manipolazione delle immagini.

Fra molteplici potenzialità esse consentono di ottenere alcune informazioni sui file immagine.

Sarà necessario avere installata nel sistema la libreria: "libgdk_pixbuf-2.0.so.0.4200.8 ".

Mostriamo un semplice esempio pratico:

Library "libgdk_pixbuf-2.0:0.4200.8"

Public Struct GdkPixbufFormat
  name As Pointer
  signature As Pointer
  domain As Pointer
  description As Pointer
  mime_types As Pointer
  extensions As Pointer
  flags As Integer
  disabled As Boolean
  license As Pointer
End Struct

' 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, GError As Pointer) As Pointer

' guchar * gdk_pixbuf_get_pixels (const GdkPixbuf *pixbuf)
' Queries a pointer to the pixel data of a pixbuf.
Private Extern gdk_pixbuf_get_pixels(GdkPixbuf As Pointer) As Pointer

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

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

' int gdk_pixbuf_get_n_channels (const GdkPixbuf *pixbuf)
' Queries the number of channels of a pixbuf.
Private Extern gdk_pixbuf_get_n_channels(GdkPixbuf As Pointer) As Integer

' gboolean gdk_pixbuf_get_has_alpha (const GdkPixbuf *pixbuf)
' Queries whether a pixbuf has an alpha channel (opacity information).
Private Extern gdk_pixbuf_get_has_alpha(GdkPixbuf As Pointer) As Boolean

' int gdk_pixbuf_get_bits_per_sample (const GdkPixbuf *pixbuf)
' Queries the number of bits per color sample in a pixbuf.
Private Extern gdk_pixbuf_get_bits_per_sample(pixbuf As Pointer) As Integer

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

' gsize gdk_pixbuf_get_byte_length (const GdkPixbuf *pixbuf)
' Returns the length of the pixel data, in bytes.
Private Extern gdk_pixbuf_get_byte_length(pixbuf As Pointer) As Long

' GdkPixbufFormat * gdk_pixbuf_get_file_info (const gchar *filename, gint *width, gint *height)
' Parses an image file far enough to determine its format and size.
Private Extern gdk_pixbuf_get_file_info(filename As String, width As Pointer, height As Pointer) As Pointer

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


Public Sub Main()

 Dim nomefile As String = "/percorso/del/file/immagine"
 Dim i, wi, hi As Integer
 Dim l As Long
 Dim pixbuf As Pointer
 Dim bo As Boolean
 Dim PixbufFormat As New GdkPixbufFormat

 pixbuf = gdk_pixbuf_new_from_file(nomefile, 0)
 If pixbuf == 0 Then Error.Raise("Errore !")
 
 Print "File immagine:            "; nomefile
 i = gdk_pixbuf_get_width(pixbuf)
 Print "Larghezza:                "; i; " pixel"
 i = gdk_pixbuf_get_height(pixbuf)
 Print "Altezza:                  "; i; " pixel"
 i = gdk_pixbuf_get_rowstride(pixbuf)
 Print "Numero di byte per riga:  "; i
 i = gdk_pixbuf_get_n_channels(pixbuf)
 Print "Canali:                   "; i
 bo = gdk_pixbuf_get_has_alpha(pixbuf)
 Print "Canale Alfa:              "; bo
 i = gdk_pixbuf_get_bits_per_sample(pixbuf)
 Print "Risoluzione:              "; i; " bit"
 l = gdk_pixbuf_get_byte_length(pixbuf)
 Print "Lunghezza dei dati pixel: "; l; " byte"
 
 g_object_unref(pixbuf)
 
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 
 PixbufFormat = gdk_pixbuf_get_file_info(nomefile, VarPtr(wi), VarPtr(hi))
 
 With PixbufFormat
   Print "\nName:        "; String@(.name)                  ' Il nome del formato immagine
   Print "Domain:      "; String@(.domain)                ' Il contrassegno del modulo
   Print "Description: "; String@(.description)           ' Il dominio del messaggio per la descrizione
   Print "Mime-Type:   "; String@(Pointer@(.mime_types))  ' Una descrizione del formato immagine
   Print "Extension:   "; String@(Pointer@(.extensions))  ' Un array di MIME-types del formato immagine
   Print "Flag:        "; .flags             ' Combinazione di flags che specifica ulteriori dettagli sulle operazioni supportate
   Print "License:     "; String@(.license)  ' Informazione sulla licenza relativa al formato immagine
 End With
 
End



Riferimenti