canvas-imlib newbie help




I'm still a newbie to gtk+ and gnome development and I'm having a
problem getting the canvas to load an Imlib image. I can get a rect or
ellipse type to draw just fine on the canvas but when I try to load an
Imlib image I just get a blank window...with the correct dimensions of
the pic. Also, I get no errors on compilation. Here's the code I have:

############################################################
#include <gnome.h>
#include <iostream.h>

int main(int argc, char* argv[])
{
  GtkWidget* mw;
  GtkWidget* canvas;
  GnomeCanvasGroup* group;
  GdkImlibImage*    pic;
  gint w, h;

  gnome_init("canvas-example", "0.1",argc, argv);
  gdk_imlib_init();

  mw = gtk_window_new(GTK_WINDOW_TOPLEVEL);

  gtk_widget_push_visual(gdk_imlib_get_visual());
  gtk_widget_push_colormap(gdk_imlib_get_colormap());
  canvas = gnome_canvas_new();
  gtk_widget_pop_visual();
  gtk_widget_pop_colormap();
  
  group = gnome_canvas_root(GNOME_CANVAS(canvas));
  pic = gdk_imlib_load_image("test_pic.jpeg");
  w = pic->rgb_width;
  h = pic->rgb_height;
  gdk_imlib_render(pic, w, h);

  gnome_canvas_item_new(group,
                        GNOME_TYPE_CANVAS_IMAGE,
                        "image", pic,
                        "x", 0,
                        "y", 0,
                        "width", w,
                        "height", h,
                        NULL);
  
  gtk_container_add(GTK_CONTAINER(mw), canvas);
  gtk_window_set_default_size(GTK_WINDOW(mw), w, h);
  gtk_widget_show_all(mw);

  gtk_main();

  return 0;
}
##################################################

And here's how I'm compiling:
g++ -Wall -g gtk_canvas_test.cpp -o gtk_canvas_test `gtk-config
--cflags` `gtk-config --libs` `gnome-config --cflags gnome gnomeui`
`gnome-config --libs gnome gnomeui` -L/usr/X11R6/include
-L/usr/X11R6/lib -lX11 -lXext -ljpeg -lpng -ltiff -lz -lgif -lglib -lgdk
-lm -lgdk_imlib

I've read every piece of documentation I could find (mostly from
developer.gnome.org) and I just can't figure out what I'm missing or
doing wrong. I'm on RH6.0, gtk+ 1.2.3-1, gnome-libs 1.0.10-2, and imlib
1.9.5-5.

Any help would be greatly appreciated.
Thanks!
Kevin Masaryk
epi@inficad.com



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