Re: 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:
[snip]
>    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);

You don't need to render the image.  The canvas takes care of it.

>    gnome_canvas_item_new(group,
>                          GNOME_TYPE_CANVAS_IMAGE,
>                          "image", pic,
>                          "x", 0,
>                          "y", 0,
>                          "width", w,
>                          "height", h,
>                          NULL);

Uh oh.  You are passing integers for the dimensions, but these arguments
of the image item are doubles.  Pass them as

    gnome_canvas_item_new(group,
                          GNOME_TYPE_CANVAS_IMAGE,
                          "image", pic,
                          "x", 0.0,
                          "y", 0.0,
                          "width", (double) w,
                          "height", (double) h,
                          NULL);

And finally, you are not setting the scrolling region of the canvas.
Call gnome_canvas_set_scroll_region() with your area of interest so
that it knows how to position the view.

  Federico



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