tonycoz / imager

Imager - image manipulation from perl.
http://imager.perl.org/
27 stars 4 forks source link

Win32 screenshot of desktop does not take monitor scaling into account #531

Open rotan-hanrahan opened 4 weeks ago

rotan-hanrahan commented 4 weeks ago

In Windows 10 with a 3840x2160 monitor with "Scale and layout" set to 125% via the Windows Display Settings, a screenshot should have the same dimensions as the physical pixel of the monitor, but instead returns an image that is 3072x1728. Note that if you multiply these incorrect dimensions by 1.25 you get 3840x2160.

use Imager::Screenshot 'screenshot';
my $im = screenshot();
my $window_width  = $im->tags(name => 'ss_window_width');
my $window_height = $im->tags(name => 'ss_window_height');
my $window_type   = $im->tags(name => 'ss_type');
print "$window_width x $window_height using $window_type\n";

The output of the above is:

3072 x 1728 using Win32

The expected output, indicating the correct screenshot dimensions, would be:

3840 x 2160 using Win32

The captured screenshot image can be written to file via:

$im->write(file => "screenshot.png", type => 'png');

The written image has been cropped to the incorrect dimensions.

tonycoz commented 3 weeks ago

Thanks, I won't be able to look at this until I get my laptop back from being repaired, which should be within a couple of weeks.

tonycoz commented 1 day ago

I've reproduced this, and multiple screens isn't working either.

I'll probably have to largely rewrite the Win32 capture.

I could just turn on hidpi awareness for the process, but that could cause windows (if any) that belong to the process to redraw