#include <X11/Xlib.h>
#include <X11/X.h>
#include <X11/Xutil.h>
unsigned long readPixel(int x, int y) {
Display *display = XOpenDisplay(NULL);
Window root = DefaultRootWindow(display);
//if screen resolution is unknown
//XWindowAttributes gwa;
//XGetWindowAttributes(display, root, &gwa);
//width = gwa.width, height = gwa.height
XImage *image = XGetImage(display, root, 0, 0, 1920, 1080, AllPlanes, ZPixmap);
unsigned long RGB = XGetPixel(image, x, y);
// R = (RGB >> 16)
// G = (RGB >> 8 & 255)
// B = (RGB & 255)
// all unsigned long
XCloseDisplay(display);
return RGB;
}
//compile with g++ $file -l X11
Ubuntu读取桌面某个点的像素
最新推荐文章于 2023-02-07 09:20:13 发布