Differenze tra le versioni di "Mostrare un'immagine con funzioni del API di GStreamer"
Riga 1: | Riga 1: | ||
La risorsa '''GStreamer''' dà la possibilità anche semplicemente di caricare un file immagine e mostrarne il contenuto. | La risorsa '''GStreamer''' dà la possibilità anche semplicemente di caricare un file immagine e mostrarne il contenuto. | ||
− | Per poter fruire delle risorse di ''GStreamer'', sarà necessario avere installata nel sistema e richiamare in Gambas la libreria dinamica condivisa: "''libgstreamer-1.0:0. | + | Per poter fruire delle risorse di ''GStreamer'', sarà necessario avere installata nel sistema e richiamare in Gambas la libreria dinamica condivisa: "''libgstreamer-1.0:0.2403.0''" |
L'immagine potrà essere mostrata in una finestra automaticamente creata dalla risorsa ''GStreamer'', oppure in una ''DrawingArea''. | L'immagine potrà essere mostrata in una finestra automaticamente creata dalla risorsa ''GStreamer'', oppure in una ''DrawingArea''. | ||
Riga 12: | Riga 12: | ||
− | Library "libgstreamer-1.0" | + | Library "libgstreamer-1.0:0.2403.0" |
Private Enum GST_STATE_VOID_PENDING = 0, GST_STATE_NULL, GST_STATE_READY, GST_STATE_PAUSED, GST_STATE_PLAYING | Private Enum GST_STATE_VOID_PENDING = 0, GST_STATE_NULL, GST_STATE_READY, GST_STATE_PAUSED, GST_STATE_PLAYING | ||
Riga 41: | Riga 41: | ||
− | + | Public Sub Main() | |
− | + | Dim fileImmagine As String | |
gst_init(0, 0) | gst_init(0, 0) | ||
Riga 50: | Riga 50: | ||
If IsNull(immago) Then Error.Raise("Impossibile creare un elemento 'playbin' !") | If IsNull(immago) Then Error.Raise("Impossibile creare un elemento 'playbin' !") | ||
− | fileImmagine = "<FONT Color= | + | fileImmagine = "<FONT Color=darkgreen>''/percorso/del/file/immagine''</font>" |
g_object_set(immago, "uri", g_filename_to_uri(fileImmagine, Null, 0), Null) | g_object_set(immago, "uri", g_filename_to_uri(fileImmagine, Null, 0), Null) | ||
Riga 65: | Riga 65: | ||
Quit | Quit | ||
− | + | End | |
− | + | Public Sub Application_Read() | |
− | + | Dim s As String | |
Input #File.In, s | Input #File.In, s | ||
Riga 77: | Riga 77: | ||
If s = "c" Then ciclo = 0 | If s = "c" Then ciclo = 0 | ||
− | + | End | |
==Immagine mostrata in una ''DrawingArea''== | ==Immagine mostrata in una ''DrawingArea''== | ||
− | Di seguito mostreremo un esempio, nel quale verrà caricato un file immagine in un'applicazione grafica. L'immagine sarà mostrata in una ''DrawingArea''. posta sul ''Form'' dell'applicazione Gambas. | + | Di seguito mostreremo un esempio, nel quale verrà caricato un file immagine in un'applicazione grafica. |
+ | <BR>L'immagine sarà mostrata in una ''DrawingArea''. posta sul ''Form'' dell'applicazione Gambas. | ||
Private immago As Pointer | Private immago As Pointer | ||
− | Library "libgstreamer-1.0" | + | Library "<FONT Color=blue>libgstreamer-1.0:0.2403.0</font>" |
Private Enum GST_STATE_VOID_PENDING = 0, GST_STATE_NULL, GST_STATE_READY, GST_STATE_PAUSED, GST_STATE_PLAYING | Private Enum GST_STATE_VOID_PENDING = 0, GST_STATE_NULL, GST_STATE_READY, GST_STATE_PAUSED, GST_STATE_PLAYING | ||
Riga 115: | Riga 116: | ||
− | Library "libgstvideo-1.0" | + | Library "<FONT Color=red>libgstvideo-1.0:0.2403.0</font>" |
<FONT Color=gray>' ''void gst_video_overlay_set_window_handle (GstVideoOverlay *overlay, guintptr handle)'' | <FONT Color=gray>' ''void gst_video_overlay_set_window_handle (GstVideoOverlay *overlay, guintptr handle)'' | ||
Riga 122: | Riga 123: | ||
− | + | Public Sub Form_Open() | |
− | + | Dim fileImmagine As String | |
gst_init(0, 0) | gst_init(0, 0) | ||
Riga 141: | Riga 142: | ||
gst_element_set_state(immago, GST_STATE_PLAYING) | gst_element_set_state(immago, GST_STATE_PLAYING) | ||
− | + | End | |
− | + | Public Sub Button1_Click() | |
Me.Close | Me.Close | ||
− | + | End | |
− | + | Public Sub Form_Close() | |
gst_object_unref(immago) | gst_object_unref(immago) | ||
− | + | End | |
− | |||
Versione delle 15:19, 3 lug 2024
La risorsa GStreamer dà la possibilità anche semplicemente di caricare un file immagine e mostrarne il contenuto.
Per poter fruire delle risorse di GStreamer, sarà necessario avere installata nel sistema e richiamare in Gambas la libreria dinamica condivisa: "libgstreamer-1.0:0.2403.0"
L'immagine potrà essere mostrata in una finestra automaticamente creata dalla risorsa GStreamer, oppure in una DrawingArea.
Immagine mostrata in una finestra creata da GStreamer
Di seguito mostreremo un esempio, nel quale verrà caricato un file immagine in un'applicazione a riga di comando. L'immagine sarà mostrata in una finestra creata da GStreamer.
Private immago As Pointer Private ciclo As Byte = 1 Library "libgstreamer-1.0:0.2403.0" Private Enum GST_STATE_VOID_PENDING = 0, GST_STATE_NULL, GST_STATE_READY, GST_STATE_PAUSED, GST_STATE_PLAYING ' gst_init (int *argc, char **argv[]) ' Initializes the GStreamer library, setting up internal path lists, registering built-in elements, and loading standard plugins. Private Extern gst_init(argc As Pointer, argv As Pointer) ' GstElement * gst_element_factory_make(const gchar *factoryname, Const gchar * name) ' Create a new element of the type defined by the given element factory. Private Extern gst_element_factory_make(factoryname As String, name As String) As Pointer ' gchar * g_filename_to_uri (const gchar *filename, const gchar *hostname, GError **error) ' Converts an absolute filename to an escaped ASCII-encoded URI. Private Extern g_filename_to_uri(filename As String, hostname As String, GError As Pointer) As String ' void g_object_set(gpointer object, const gchar *first_property_name, ...) ' Sets properties on an object. Private Extern g_object_set(gobject As Pointer, key As String, value As String, tertium As String) ' GstStateChangeReturn gst_element_set_state(GstElement *element, GstState state) ' Sets the state of the element. Private Extern gst_element_set_state(gstelement As Pointer, state As Integer) As Integer ' void gst_object_unref(gpointer object) ' Decrements the reference count on object. Private Extern gst_object_unref(gobject As Pointer) Public Sub Main() Dim fileImmagine As String gst_init(0, 0) immago = gst_element_factory_make("playbin", "immagine") If IsNull(immago) Then Error.Raise("Impossibile creare un elemento 'playbin' !") fileImmagine = "/percorso/del/file/immagine" g_object_set(immago, "uri", g_filename_to_uri(fileImmagine, Null, 0), Null) ' Mostra l'immagine: gst_element_set_state(immago, GST_STATE_PLAYING) While ciclo Wait 0.01 Wend gst_object_unref(immago) Quit End Public Sub Application_Read() Dim s As String Input #File.In, s ' Arresta la riproduzione del file immagine: If s = "c" Then ciclo = 0 End
Immagine mostrata in una DrawingArea
Di seguito mostreremo un esempio, nel quale verrà caricato un file immagine in un'applicazione grafica.
L'immagine sarà mostrata in una DrawingArea. posta sul Form dell'applicazione Gambas.
Private immago As Pointer Library "libgstreamer-1.0:0.2403.0" Private Enum GST_STATE_VOID_PENDING = 0, GST_STATE_NULL, GST_STATE_READY, GST_STATE_PAUSED, GST_STATE_PLAYING ' gst_init (int *argc, char **argv[]) ' Initializes the GStreamer library, setting up internal path lists, registering built-in elements, and loading standard plugins. Private Extern gst_init(argc As Pointer, argv As Pointer) ' GstElement * gst_element_factory_make(const gchar *factoryname, Const gchar * name) ' Create a new element of the type defined by the given element factory. Private Extern gst_element_factory_make(factoryname As String, name As String) As Pointer ' gchar * g_filename_to_uri (const gchar *filename, const gchar *hostname, GError **error) ' Converts an absolute filename to an escaped ASCII-encoded URI. Private Extern g_filename_to_uri(filename As String, hostname As String, GError As Pointer) As String ' void g_object_set(gpointer object, const gchar *first_property_name, ...) ' Sets properties on an object. Private Extern g_object_set(gobject As Pointer, key As String, value As String, tertium As String) ' GstStateChangeReturn gst_element_set_state(GstElement *element, GstState state) ' Sets the state of the element. Private Extern gst_element_set_state(gstelement As Pointer, state As Integer) As Integer ' void gst_object_unref(gpointer object) ' Decrements the reference count on object. Private Extern gst_object_unref(gobject As Pointer) Library "libgstvideo-1.0:0.2403.0" ' void gst_video_overlay_set_window_handle (GstVideoOverlay *overlay, guintptr handle) ' Calls the video overlay's set_window_handle method. Private Extern gst_video_overlay_set_window_handle(overlay As Pointer, handle As Integer) Public Sub Form_Open() Dim fileImmagine As String gst_init(0, 0) immago = gst_element_factory_make("playbin", "immagine") If IsNull(immago) Then Error.Raise("Impossibile creare un elemento 'playbin' !") fileImmagine = "/percorso/del/file/immagine" g_object_set(immago, "uri", g_filename_to_uri(fileImmagine, Null, 0), Null) ' Imposta la "DrawingArea" come superficie per la riproduzione dell'immagine: gst_video_overlay_set_window_handle(immago, DrawingArea1.Handle) ' Mostra l'immagine: gst_element_set_state(immago, GST_STATE_PLAYING) End Public Sub Button1_Click() Me.Close End Public Sub Form_Close() gst_object_unref(immago) End