Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Screen Capture #152

Merged
merged 32 commits into from
Feb 4, 2016
Merged

Implement Screen Capture #152

merged 32 commits into from
Feb 4, 2016

Conversation

octalmage
Copy link
Owner

Overview

This is the first piece of the "bitmap" related functionality. In its current state, it allows you to read the screen much quicker than getPixelColor. The next priority is to allow you to save a screen capture to a file. This PR breaks compatibility with Node.js 0.8.x, if anyone has an issue with this speak up now!

Special thanks to @Deltatiger for solving a critical issue, and @demipixel for testing.

Usage

let robot = require("robotjs");

//Get a 100x100 screen capture starting at 0, 0. 
let img = robot.screen.capture(0, 0, 100, 100);

console.log(img.width)

//Get pixel color at 50, 50.
let hex = img.colorAt(50, 50);
console.log(hex);

Reviewers

TODO

  • Write documentation.

Related

#13
#4 - This is the start of the new function naming convention.

@octalmage octalmage added this to the First Stable Release milestone Jan 6, 2016
@octalmage
Copy link
Owner Author

Just remembered that I wanted to update the Appveyor and TravisCI config to include newer versions of Node.js, and allow 0.8.x to fail. Here's what I came up with:

https://gist.github.com/octalmage/326fffd925f8e517a961

Might be overkill, I'll work on getting this in tomorrow.

@Deltatiger
Copy link
Collaborator

@octalmage So I tried writing the data as a Bitmap file. Unfortunately this is taking a lot of space. Since I had to write as raw bytes I got some 8Mb for a screen of size 1920x1080. But the same only takes about 1Mb when I do a printscreen and paste it in Paint. So we may have to do some compression before storing it to the file system.

@octalmage
Copy link
Owner Author

Did you see my bitmap-save branch? Bitmaps are larger in general, I'm sure that saving to a png will be much better.

I did a ton of benchmarking and after taking a full screen capture, Node.js used around 4mb.

@Deltatiger
Copy link
Collaborator

@octalmage I will take a look into it. PNG has advantages but do we not need external libraries to convert it to PNG ?

@octalmage
Copy link
Owner Author

@Deltatiger we'll need to include libpng for Windows, but it shouldn't be that difficult. Just need to figure out how to link the library with node-gyp. I'm sure someone has done it!

@octalmage octalmage removed the blocked label Jan 8, 2016
@octalmage
Copy link
Owner Author

@Deltatiger alright this is ready! The tests are running now and they should all pass.

How does this look to you?

@Deltatiger
Copy link
Collaborator

@octalmage Honestly speaking I am not that experienced with TravisCI or Appveyor. Just starting to learn those. If this looks good to you, go ahead. I am not that experienced just yet.

@octalmage
Copy link
Owner Author

@Deltatiger Thanks! I was mostly worried about the screen capture code. I'm going to merge it!

octalmage added a commit that referenced this pull request Feb 4, 2016
@octalmage octalmage merged commit a09562e into master Feb 4, 2016
@marcusdiy
Copy link

robot.screen.capture() will not capture the full screen on windows 4k monitor.
The screen resolution is: 3840x2160 but the screenshot uses 2194x1234 "software resolution"
witch results in cropped/partial screenshot

Setting RobotJs.screen.capture(0, 0, 3840, 2160) fixes
seems like the capture() uses the values from robot.getScreenSize() which may be different on higher density screens

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants