1 Jan 2003 01:28
Help request: gnome-canvas and images from data
Frazer Williams <pfw <at> moi.unl.edu>
2003-01-01 00:28:05 GMT
2003-01-01 00:28:05 GMT
Hi,
I'm trying to understand how to use gnome-canvas to display images, and
I could use some help/advice.
I've figured out how to display a .png image from a file on the canvas,
but I've bogged down on displaying an image from data (the functionality
provided by gdk-pixbuf_new_from_data(), for example).
Two approaches I've tried that almost seem to work are (I've attached
the code at the end):
1. Create a pixbuf with gdk_pixbuf_new_from_data() and a blank drawable
with gdk_pixmap_new(), fill in the drawable using
gdk_pixbuf_render_to_drawable(), and then add it to the canvas with
gnome_canvas_item_new() using the GNOME_TYPE_CANVAS_WIDGET
type and providing the argument pair "widget" and a pointer to the
drawable cast as a (GtkWidget *).
2. Create a blank drawable with gdk_pixbuf_new(), draw the data into
the drawable with gdk_draw_rgb_image(), and add the drawable to the
canvas as above using gnome_canvas_item_new() and the
GNOME_TYPE_WIDGET type.
Both methods produce a blank canvas, and a warning from GnomeUI:
GnomeUI-WARNING **: gnome_canvas_item_construct(): invalid unclassed object pointer for argument
type `GtkObject'
(Continue reading)
#include <gnome.h>
#define WIDTH 700
#define HEIGHT 600
static gint delete_event_cb(GtkWidget *window, GdkEventAny *e, gpointer data);
GtkWidget *app;
static void
free_pixels(guchar* pixels, gpointer data)
{
g_free(pixels);
}
static void
create_canvas_items(GtkWidget *canvas)
{
GdkPixbuf *pixbuf;
guchar *pixels;
GnomeCanvasItem *citem;
RSS Feed