Skip to content

Commit 4ee403f

Browse files
committed
fix: modify getDisplayDPI() to handle Windows DPI misreporting
- Added check for Windows systems where Toolkit.getScreenResolution() incorrectly reports 96 DPI on high-DPI screens. - Force 2x scaling for Windows if DPI is 96 to ensure correct display scaling. - Maintain normal 2x scaling for DPI >= 144, fallback to 1x for lower DPI.
1 parent c39d62c commit 4ee403f

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

core/src/processing/core/PImage.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,18 @@ private void init(int width, int height, int format, int factor,
281281
(ACHIEVE HIGH-DPI BY DEFAULT)
282282
Change access modifier as needed.
283283
*/
284-
private int getDisplayDPI() {
285-
int dpi = Toolkit.getDefaultToolkit().getScreenResolution();
286-
return dpi > 0 ? dpi : 1; // Fallback to 1 if DPI cannot be determined
284+
protected int getDisplayDPI() {
285+
int dpi = Toolkit.getDefaultToolkit().getScreenResolution();
286+
287+
// On Windows, always assume 2x if Toolkit misreports 96 DPI
288+
if (dpi == 96 && System.getProperty("os.name").toLowerCase().contains("win")) {
289+
return 2;
290+
}
291+
292+
return (dpi >= 144) ? 2 : 1; // 2x for high DPI, 1x otherwise
287293
}
288294

295+
289296
/**
290297
* Check the alpha on an image, using a really primitive loop.
291298
*/

0 commit comments

Comments
 (0)