Jump to content

Color of a screen pixel: Difference between revisions

→‎{{header|Python}}: added pywin32 version
(removed useless RGBX -> RGB conversion)
(→‎{{header|Python}}: added pywin32 version)
Line 67:
import PIL.ImageGrab
return PIL.ImageGrab.grab().load()[i_x, i_y]
 
print get_pixel_colour(0, 0)</lang>
{{libheader|PIL}}
Line 77 ⟶ 78:
o_x_image = o_x_root.get_image(i_x, i_y, 1, 1, Xlib.X.ZPixmap, -1)
o_pil_image_rgb = PIL.Image.fromstring("RGB", (1, 1), o_x_image.data, "raw", "BGRX")
f_colourlf_colour = PIL.ImageStat.Stat(o_pil_image_rgb).mean
i_colourli_colour = map(int, f_colourlf_colour)
return i_colourli_colour
 
print get_pixel_colour(0, 0)</lang>
{{libheader|PyQt}}
Line 86 ⟶ 88:
app = PyQt4.QtGui.QApplication([])
long_qdesktop_id = PyQt4.QtGui.QApplication.desktop().winId()
long_qcolorlong_colour = PyQt4.QtGui.QPixmap.grabWindow(long_qdesktop_id).toImage().pixel(i_x, i_y)
i_qcolori_colour = int(long_qcolorlong_colour)
return ((i_qcolor & 0xff0000)i_colour >> 16), ((i_qcolor & 0xff000xff), ((i_colour >> 8) & 0xff), (i_qcolori_colour & 0xff)
 
print get_pixel_colour(0, 0)</lang>
{{libheader|PyGTK}}
Line 96 ⟶ 99:
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)
return o_gdk_pixbuf.get_pixels_array().tolist()[0][0]
 
print get_pixel_colour(0, 0)</lang>
{{libheader|pywin32}}
<lang python>def get_pixel_colour(i_x, i_y):
import win32gui
i_desktop_window_id = win32gui.GetDesktopWindow()
i_desktop_window_dc = win32gui.GetWindowDC(i_desktop_window_id)
long_colour = win32gui.GetPixel(i_desktop_window_dc, 0, 0)
i_colour = int(long_colour)
return (i_colour & 0xff), ((i_colour >> 8) & 0xff), ((i_colour >> 16) & 0xff)
 
print get_pixel_colour(0, 0)</lang>
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.