Sorry, reposting the previous message with rich-formatting enabled.

Hi all.

I managed to procure the following code from
http://rosettacode.org/wiki/Color_of_a_screen_pixel, that retrieves the
pixel color values.
This works in gtk.


#######################################################
import gtk
import gobject

def get_pixel_colour(i_x, i_y):
    o_gdk_pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, 1, 1)
    o_gdk_pixbuf.get_from_drawable(gtk.gdk.get_default_root_window(),
gtk.gdk.colormap_get_system(), i_x, i_y, 0, 0, 1, 1)
    print tuple(o_gdk_pixbuf.get_pixels_array().tolist()[0][0])

def f():
    for i in range(0, 50):
        get_pixel_colour(5, i)

win = gtk.Window()
win.show()

gobject.timeout_add(5000, f)

gtk.main()
#######################################################



Now, as the next thing, I would require the way to "set" color in a pixel,
given its x- and y-coordinates.


Any ideas please? :)



On Sat, Jul 6, 2013 at 7:23 PM, Ajay Garg <ajaygargn...@gmail.com> wrote:

> Hi all.
>
> I managed to procure the following code from
> http://rosettacode.org/wiki/Color_of_a_screen_pixel, that retrieves
> the pixel color values.
> This works in gtk.
>
>
> #######################################################
> import gtk
> import gobject
>
> def get_pixel_colour(i_x, i_y):
>     o_gdk_pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, 1, 1)
>     o_gdk_pixbuf.get_from_drawable(gtk.gdk.get_default_root_window(),
> gtk.gdk.colormap_get_system(), i_x, i_y, 0, 0, 1, 1)
>     print tuple(o_gdk_pixbuf.get_pixels_array().tolist()[0][0])
>
> def f():
>     for i in range(0, 50):
>         get_pixel_colour(5, i)
>
> win = gtk.Window()
> win.show()
>
> gobject.timeout_add(5000, f)
>
> gtk.main()
> #######################################################
>
>
>
> Now, as the next thing, I would require the way to "set" color in a
> pixel, given its x- and y-coordinates.
>
>
> Any ideas please? :)
>
>
> On Sat, Jul 6, 2013 at 6:36 PM, Ajay Garg <ajaygargn...@gmail.com> wrote:
> > Hi all.
> >
> > How can we get the color of each pixel on the "current screen"
> > (possibly beginning from
> > http://www.pygtk.org/docs/pygtk/class-gdkscreen.html)?
> >
> > The use-case is as follows ::
> >
> >     * Let's say, I compare two rows of pixels on the current screen.
> >     * The first row is "all white".
> >     * The second row is interspersed with "black and white".
> >     * For every such "black and white" row, replace it with an "all
> white" row.
> >
> >
> >
> > I am a coder myself, so all I need are some pointers :)
> >
> > Looking forward to some help :)
> >
> >
> > Thanks and Regards,
> > Ajay
>
>
>
> Thanks and Regards,
> Ajay
>



-- 
Regards,
Ajay
_______________________________________________
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Reply via email to