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
Make screen.find() more convenient on high-DPI devices #211
Conversation
When capturing a screen region in a recent Windows version on a high-DPI device, the captured image can have a much higher resolution than scale-unaware applications such as `node.exe` might think (compare also nut-tree/libnut-core#52). For convenience, let's support scaling the "needle" image that `nut.js` is told to find. For example, on my laptop, where the scale factor is 200%, I would capture a rectangular region, save it as a `.png` file, then tell `nut.js` to find it thusly: await screen.find('needle.png', 10000, { scaleNeedle: true }) Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
The |
Hi @dscho 👋 Thanks for your contributions! I‘ll get back to you once things have settled a bit. Best regards Simon |
Sounds good. All the best for your move. |
Hi @dscho, I finally found some time to review both #211 and nut-tree/libnut-core#52.
When I first reviewed your PRs I've been a bit overwhelmed by their changes. Especially the runtime library loading and image resizing got me thinking about alternative ways to deal with high DPI screens on Windows. I'd love My implementation is only concerning Unfortunately I'm only running a Windows VM for development, so if you want to test my approach on an actual machine, I'd love to hear your feedback. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given a way to solve this issue without applying changes to nut.js
I'd love to discuss possible solutions
I tested this, and it doesn't work for me. My screen is 3240 x 2160 pixels, but even with your patch, libnut reports it to be 1620 x 1080. |
Aargh, I looked at the wrong data. Your patch is actually really good! Might I suggest just one thing? The following diff should make people with multi-screen setups happy: diff --git a/src/win32/screengrab.c b/src/win32/screengrab.c
index 6842c6e..93c32a9 100644
--- a/src/win32/screengrab.c
+++ b/src/win32/screengrab.c
@@ -9,8 +9,8 @@ MMRect getScaledRect(MMRect input, HDC imageSource) {
HGDIOBJ hBitmap = GetCurrentObject(imageSource, OBJ_BITMAP);
GetObject(hBitmap, sizeof(BITMAP), &structBitmapHeader);
- size_t desktopWidth = (size_t)GetSystemMetrics(SM_CXSCREEN);
- size_t desktopHeight = (size_t)GetSystemMetrics(SM_CYSCREEN);
+ size_t desktopWidth = (size_t)GetSystemMetrics(SM_CXVIRTUALSCREEN);
+ size_t desktopHeight = (size_t)GetSystemMetrics(SM_CYVIRTUALSCREEN);
double scaleX = (double)(structBitmapHeader.bmWidth / desktopWidth);
double scaleY = (double)(structBitmapHeader.bmHeight / desktopHeight); This will grab a full screenshot that encloses all attached screens as far as I understand (I cannot test this, though, I only have a single screen). |
Hi @dscho 👋 I used Thanks for your feedback, I’m happy to have an actual Windows user test this. I’m limited to a Mac and several VMs. So if you’re interested you might want to join our Discord? |
Fair enough!
I'd love to, but I fear that would be too much of a time commitment for me. |
When capturing a screen region in a recent Windows version on a high-DPI device, the captured image can have a much higher resolution than scale-unaware applications such as
node.exe
might think (compare also this PR).For convenience, let's support scaling the "needle" image that
nut.js
is told to find.For example, on my laptop, where the scale factor is 200%, I would capture a rectangular region, save it as a
.png
file, then tellnut.js
to find it thusly: