Anonymous user
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")
return
print get_pixel_colour(0, 0)</lang>
{{libheader|PyQt}}
Line 86 ⟶ 88:
app = PyQt4.QtGui.QApplication([])
long_qdesktop_id = PyQt4.QtGui.QApplication.desktop().winId()
return ((
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>
|