Re: How to get pixel values along a line?



On Tue, 2007-04-10 at 15:02 +0200, Fredrik Persson wrote:
> I writing a gtk application where I need to do the following; let the
> user mark two pixels in a drawingarea (as you would if you were to
> draw a line in, for example, the gimp) and then, somehow, have the
> pixel values along that line be returned to me in some form. The goal
> is to present a graph to the user with those pixel values. 
> 
> The problem at hand is; how do I get those pixel values?
> 
> (And I'm writing this in pyhon, so if someone wants to provide code
> examples in python, that would be great.)

The only way to get information back from a GtkDrawingArea is in a
really round-about, slow way.  It would involve round-trip calls to the
server as the GtkDrawingArea's Gdk window lives on the X-server.  To get
pixel values would require one server call (and network transmission)
for each pixel you want to query.  This is very very slow.

The best way to do what you are trying to do is to have a GdkPixbuf
backing store that your program draws to, which is rendered to the
GtkDrawingArea on expose or configure, or update.  Since the GdkPixbuf
is local (not server), you can easily query it's RGB data directly.  You
likely already have a Pixbuf (or some other object) to be a backing
store for the GtkDrawingArea, as you'd need to account for redraws
anyway.  Anyway, I think this is the direction you probably need to go.

Michael


> 
> TIA!
> 
> /Fredrik Persson 
> _______________________________________________
> gtk-list mailing list
> gtk-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-list




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