简体   繁体   English

从屏幕获取像素颜色

[英]getting a pixel color from screen

I'm trying to find out the color value of a specific pixel(which will be specified using screen coordinates(100,100) for example) using xlib, this is a cli tool. 我正在尝试使用xlib找出特定像素的颜色值(例如,将使用屏幕坐标(100,100)进行指定),这是一个cli工具。

here's some code I have been trying out(no dice): 这是我一直在尝试的一些代码(没有骰子):

Display *display;
    display = XOpenDisplay(NULL);
    Window root = XDefaultRootWindow(display);
    XImage *image;
    image = XGetImage(display,root,0,0,1,1,AllPlanes,XYPixmap);
    printf("pixel:%lu\n",XGetPixel(image,0,0));
    XCloseDisplay(display);

it always prints 0 if I change tthe x,y value of XGetPixel to a value other than 0 如果我将XGetPixel的x,y值更改为0以外的值,它将始终输出0

maybe I'm looking in the wrong place or using teh wrong functions 也许我在错误的地方寻找或使用错误的功能

thanks 谢谢

我忘了改变1,1的宽度设置正确地修复了一切

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM