octalmage / robotjs

Node.js Desktop Automation.
http://robotjs.io
MIT License
12.38k stars 961 forks source link

Problem with colorAt and screen.capture #626

Open swolly opened 3 years ago

swolly commented 3 years ago

Expected Behavior

When you capture a screen with screenCapture: var img = robot.screen.capture(x ,y, width, height);

and define x and y the variable img should have a x and y (img.x, img.y) which is not the case.

Current Behavior

variable doesn't get X and Y value it says undefined if you log it. Also when you want to capture a certain area where x>0 and y>0 then the colorAt method will be broken and gives wrong color codes.

Possible Solution

I have no clue.

Steps to Reproduce (for bugs)

So what I am trying to do is creating a capture of the position of my client. When I print the raw Bitmap data to a file the capture seems to be fine and takes a screenshot of my client.

var minClientX = 582, minClientY = 296, ClientWidth = 761, ClientHeight = 500;
var img = robot.screen.capture(minClientX, minClientY, ClientWidth, ClientHeight);
var mouse = robot.getMousePos();
var sample_color = img.colorAt(mouse.x, mouse.y);

 console.log("Image x: " + img.x + " Image y: " + img.y)
 console.log("Mouse Pos X: " + mouse.x + " Mouse Pos Y: " + mouse.y)
 console.log("Mouse hovered over Color: " + sample_color)

When I now hover over my client it logs me mostly #FFFFFF which is white... However when I choose the value 0 for x and y and drag my client to the top left corner of my display it seems to work...

I hope to get some help...

All regards, Swolly Unbenannt

Context

Well I'm stuck right now since I cannot continue with my project...

Your Environment