Re: GtkImageViewer



Hello Eduardo,

Thanks for the feedback.

Regarding the drawing of polygons, I have had the same problem and the solution I made is outside the GtkImageViewer. Please download my program giv at giv.sf.net and have a look at the the pair of files giv_backstore.[ch] that provide a way of quickly storing all the information under a line and then restoring it. By tieing it to the button press and motion events it is possible to get a rubberband effect with only minimal flicker. (I'm considering a rewrite that eliminates flicker all together). See giv's use of it for details. (I agree it is also worthy of a tutorial. We'll see if I'll get around to it.)

Once you have a fixed line of the polygon, I add it to the lines drawn by the annotate callback, since update time is no longer an issue.

Regarding why your example doesn't work, I don't know, but it might have to do with the fact that you fix the pixbuf format to RGB24 without checking whether your pixbuf has an alpha channel.

Good luck!

Also, next time, please send the questions to the gtk-list. I take the freedom of CC:ing it.

Regards,
Dov

2009/4/10 Eduardo J. Andres <eduardoj andres gmail com>
Dear Dov

I have been working with the widget during last days and have had  not success to get my requirement.

It is to draw with cairo and the mouse  poligons and lines as overlay of the image pixbuf. Poligons will have a lot of points so the best aproach I have seen is to draw them on the pixbuf an draw the new pixbuf to the image. But it is so slow doing it on the "image_annotate" handler.

 I have seen a number of issues at that point, for example the idea to get the cairo surface from your tutorial

int img_width = gdk_pixbuf_get_width(pixbuf);
int img_height = gdk_pixbuf_get_height(pixbuf);

cairo_surface_t *surface
= cairo_image_surface_create_for_data(gdk_pixbuf_get_pixels(pixbuf),
CAIRO_FORMAT_RGB24,
img_width,
img_height,
gdk_pixbuf_get_rowstride(pixbuf));
cairo_t *cr = cairo_create (surface);
cairo_translate(cr, -shift_x, -shift_y);
cairo_scale(cr, scale_x, scale_y);

// Now do any cairo commands you want, but you have to swap
// R and B in set_source_rgba() commands because of cairo and
// pixbuf incompabilitities.
cairo_set_source_rgba (cr, 0,0,1.0,0.5);
cairo_arc(cr,
-1, 0,
3, 0.0, 2*G_PI);
cairo_fill(cr);

cairo_set_source_rgba (cr, 1.0,0,0,0.5);
only works when you do inside the image annotate. In any other situation, the cairo drawing does not get the color. I have got, for example, the cairo surface from the pixbuf inside the gtk_image_viewer_new() function and draw directly there , but it gets a wrong color. It doesn´t matter the swapping in betweem the R and B colors. On the attached image, the rect line is has been drawn direcly with the code above, inside the the new() function. The symbol, drawnd on the GtkImageViewer->window, inside gtk_image_viever_expose().

Would you be kind to indicate me any sugesstion how to do it.

Thanks
Eduardo



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