How to draw an RGB image?



Hello,

I'm taking my first steps developing a small Gtk application
(using Glade) and I'm beginning to understand how everything
works. However I'm at a complete loss trying to draw an RGB
image into a Gtk widget.

I'm assuming that I must use a gtk_drawingarea widget, and
somehow use gdk_draw_rgb_image() in order to get the data into
it. After getting totally lost in the deeper levels of the Gtk
and Gdk APIs and header files, I just typed the following and
let go:

-----------
        [...]
        img_area = lookup_widget(GTK_WIDGET(main_window),
                "drawingarea1");
                
        /* For non-Glade people: img_area now points to a
        gtk_drawingarea of sufficient size */
                
        buf = malloc(3*WIDTH*HEIGHT*sizeof *buf);
        
        /* let's just use whatever random data happens to be
           pointed at by buf */
  
        gdk_draw_rgb_image(
                img_area->window,
                &gc,
                0, 0, WIDTH, HEIGHT,
                GDK_RGB_DITHER_NONE,
                buf,
                3*WIDTH*sizeof *buf
        );
        [...]
------------

Unsurprisingly, this thing crashed immediately with a segfault.
It generates no warning when compiled without the call to
gdk_draw_rgb_image(), so I'm assuming that the call to
lookup_widget() succeeds.

OK, can anybody point me in the right direction? What does it
take to get an image onto the screen? Since the image is supposed
to change while the app is running I must use a client-side
image.

Thanks,
--D.





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]