Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can use a <a href="http://library.gnome.org/devel/gtk/stable/GtkDrawingArea.html" rel="nofollow">GtkDrawingArea</a> and draw the images on it using <a href="http://library.gnome.org/devel/gdk/stable/gdk-Cairo-Interaction.html" rel="nofollow">cairo</a>:</p> <p>Example:</p> <pre class="lang-c prettyprint-override"><code>#include &lt;cairo.h&gt; #include &lt;gtk/gtk.h&gt; cairo_surface_t * sea_surface; cairo_surface_t * fish_surface; gboolean on_expose_event(GtkWidget * widget, GdkEventExpose * event, gpointer data) { // Create the cairo instance. cairo_t * cr = gdk_cairo_create(widget-&gt;window); // Draw the sea background. cairo_set_source_surface(cr, sea_surface, 0.0, 0.0); cairo_paint(cr); // Draw the fish. cairo_set_source_surface(cr, fish_surface, 50.0, 50.0); cairo_paint(cr); // Destroy the cairo instance. cairo_destroy(cr); return FALSE; } int main(int argc, char * argv[]) { gtk_init(&amp;argc, &amp;argv); // Load images. sea_surface = cairo_image_surface_create_from_png("sea.png"); fish_surface = cairo_image_surface_create_from_png("fish.png"); // Create window. GtkWidget * window; window = gtk_window_new(GTK_WINDOW_TOPLEVEL); g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL); gtk_window_set_default_size(GTK_WINDOW(window), 320, 240); // Create drawing area where we're going to draw our images. GtkWidget * drawing_area = gtk_drawing_area_new(); g_signal_connect(G_OBJECT(drawing_area), "expose-event", G_CALLBACK(on_expose_event), NULL); gtk_container_add(GTK_CONTAINER(window), drawing_area); // Show window and start gtk main loop. gtk_widget_show_all(window); gtk_main(); // Clean-up. cairo_surface_destroy(fish_surface); cairo_surface_destroy(sea_surface); return 0; } </code></pre> <p>To compile it on linux use:</p> <pre><code>gcc -Wall -g images.c -o images `pkg-config --cflags --libs gtk+-2.0` </code></pre> <hr> <p>Documentation:</p> <ul> <li><a href="http://library.gnome.org/devel/gtk/stable/GtkDrawingArea.html" rel="nofollow">http://library.gnome.org/devel/gtk/stable/GtkDrawingArea.html</a></li> <li><a href="http://library.gnome.org/devel/gdk/stable/gdk-Cairo-Interaction.html" rel="nofollow">http://library.gnome.org/devel/gdk/stable/gdk-Cairo-Interaction.html</a></li> <li><a href="http://www.cairographics.org/manual/cairo-cairo-t.html" rel="nofollow">http://www.cairographics.org/manual/cairo-cairo-t.html</a></li> </ul> <p>Examples:</p> <ul> <li><a href="http://www.tortall.net/mu/wiki/PyGTKCairoTutorial" rel="nofollow">http://www.tortall.net/mu/wiki/PyGTKCairoTutorial</a></li> <li><a href="http://www.zetcode.com/tutorials/cairographicstutorial/cairoimages/" rel="nofollow">http://www.zetcode.com/tutorials/cairographicstutorial/cairoimages/</a></li> </ul> <hr> <p>EDIT: If you need to be able to do this from Java, you can use <a href="http://java-gnome.sourceforge.net/" rel="nofollow">java-gnome</a> which provides bindings for both GTK and <a href="http://www.cairographics.org/cairo-java/" rel="nofollow">cairo</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload