Desktopmagic icon indicating copy to clipboard operation
Desktopmagic copied to clipboard

Screenshots are incorrectly cropped on high-DPI displays

Open ivan opened this issue 9 years ago • 4 comments

That is, I need to fix https://github.com/ludios/Desktopmagic#known-issues

I tested 64-bit Python 2.7.9 which had this problem. Haven't tested Python 3.x yet.

Not sure if this is even possible to work around without shipping our own executable.

ivan avatar Jun 17 '15 22:06 ivan

LogicalToPhysicalPointForPerMonitorDPI https://github.com/justinfrankel/licecap/commit/d7035ae9d4b27236fef2cf0ddd68b05c13080412

ivan avatar Feb 05 '17 08:02 ivan

I don't actually use Desktopmagic (I followed a link here from this issue in Pillow) but we had a similar issue with screen captures on monitors with nonstandard DPI settings in Caster and solved it using the SetProcessDpiAwareness Windows API call to tell Windows to use one-to-one pixel mapping for the process. I downloaded Desktopmagic and added the following code near the top of the file, before def checkRect(rect):.

error_code = ctypes.windll.shcore.SetProcessDpiAwareness(2)  #enable 1-1 pixel mapping
if error_code == -2147024891:
    raise OSError("Failed to set app awareness")

And that seemed to work for me. I don't have access to a high DPI monitor, but we found that, for us, the issue was also reproducible by changing the text scaling setting in the display settings for Windows and that's how I tested it just now. But I also didn't test very thoroughly, so YMMV and this should probably be tested by someone with a high DPI display before incorporating it into the code.

chilimangoes avatar Jun 06 '19 00:06 chilimangoes

Interesting, thanks. That seems like it would work for a lot of applications that use Desktopmagic, but putting it into Desktopmagic itself could interfere with a GUI program that expects the default DPI awareness.

That seems like a good workaround that people could use in their own applications, though.

ivan avatar Jun 06 '19 00:06 ivan

Yeah, I forgot to add that caveat. TBH, I don't know exactly what effects it might have since Caster is the only place I've used it, and it didn't have any ill effects on what little UI caster has. Another option might be to store the current setting from GetProcessDpiAwareness before making the change, then take the screenshot, and revert back to the original setting. Or there might be something else in the shellscalingapi functions that would be of use for doing the scaling manually.

chilimangoes avatar Jun 06 '19 00:06 chilimangoes