Autore Topic: Ottenere alcune informazioni su un file immagine con l'API di gdk_pixbuf  (Letto 195 volte)

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.178
  • Ne mors quidem nos iunget
    • Mostra profilo
Utilizzando talune funzioni esterne della libreria condivisa "libgdk_pixbuf-2.0.so", è possibile ottenere alcune informazioni relative ad un file immagine.

Mostriamo un esempio pratico:

Codice: [Seleziona]
Library "libgdk_pixbuf-2.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_n_channels (const GdkPixbuf *pixbuf)
' Queries the number of channels of a pixbuf.
Private Extern gdk_pixbuf_get_n_channels(pixbuf 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(pixbuf 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_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

' int gdk_pixbuf_get_rowstride (const GdkPixbuf *pixbuf)
' Queries the rowstride of a pixbuf, which is the number of bytes between the start of a row and the start of the next row.
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

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


Public Sub Main()

  Dim pb As Pointer
  Dim i As Integer
  Dim bo As Boolean
  Dim l As Long
 
   pb = gdk_pixbuf_new_from_file("/percorso/del/file/immagine", 0)
   If pb = 0 Then Error.Raise("ERRORE !")
   
   i = gdk_pixbuf_get_n_channels(pb)
   Print i
   
   bo = gdk_pixbuf_get_has_alpha(pb)
   Print bo
   
   i = gdk_pixbuf_get_bits_per_sample(pb)
   Print i
   
   i = gdk_pixbuf_get_width(pb)
   Print i
   
   i = gdk_pixbuf_get_height(pb)
   Print i
   
   i = gdk_pixbuf_get_rowstride(pb)
   Print i
   
   l = gdk_pixbuf_get_byte_length(pb)
   Print l
   
   g_object_unref(pb)

End
« Ultima modifica: 08 Febbraio 2018, 03:27:04 da vuott »
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »