Ottenere dati grezzi di un file immagine mediante le funzioni del API di GDK-PixBuf

Da Gambas-it.org - Wikipedia.
Versione del 26 nov 2014 alle 19:44 di Vuott (Discussione | contributi) (Creata pagina con ''''GDK-PixBuf''' è una libreria grafica per il caricamento e la manipolazione delle immagini. Alcune sue funzioni ci consentono di ottenenre un ''Puntatore'' ai dati grezzi ...')

(diff) ← Versione meno recente | Versione attuale (diff) | Versione più recente → (diff)

GDK-PixBuf è una libreria grafica per il caricamento e la manipolazione delle immagini.

Alcune sue funzioni ci consentono di ottenenre un Puntatore ai dati grezzi dei file immagine, e così di poterli estrarre.


Sarà necessario avere installata nel sistema la libreria: libgtk-3.so.0.1000.8


Mostriamo un semplice esempio pratico:

Library "libgtk-3:0.1000.8"

' 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


Public Sub Main()

 Dim nomefile As String = "/percorso/del/file/immagine"
 Dim w, h As Integer
 Dim Pixbuf, dati As Pointer
 Dim b, c As Byte
 Dim bo As Boolean
 Dim st As Stream
 Dim i As Integer

  Pixbuf = gdk_pixbuf_new_from_file(nomefile, 0)

  w = gdk_pixbuf_get_width(Pixbuf)
  Print "Larghezza: "; Null, w; " pixel"
  h = gdk_pixbuf_get_height(Pixbuf)
  Print "Altezza: "; Null, h; " pixel"
  c = gdk_pixbuf_get_n_channels(Pixbuf)
  Print "Canali: "; Null, c
  bo = gdk_pixbuf_get_has_alpha(Pixbuf)
  Print "Canale Alfa: "; Null, bo

  dati = gdk_pixbuf_get_pixels(Pixbuf)

' Dereferenziamo il Puntatore con i "Memory Stream", e ne leggiamo i valori contenuti (i dati/byte grezzi dei pixel) dell'immagine:
  st = Memory dati For Read
  For i = 0 To (w * h * c) - 1
    Read #st, b
    Print i, Hex(b)
  Next

  st.Close

End



Riferimenti