Skip to content

Commit c39d62c

Browse files
authored
Set default pixel density to the display's density.
This is aimed at achieving a High DPI by default for displays that support it.
1 parent 316a902 commit c39d62c

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

core/src/processing/core/PImage.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
package processing.core;
2626

2727
import java.awt.Image;
28+
import java.awt.Toolkit;
2829
import java.io.BufferedOutputStream;
2930
import java.io.File;
3031
import java.io.FileOutputStream;
@@ -200,7 +201,7 @@ public PImage() {
200201
* @param height image height
201202
*/
202203
public PImage(int width, int height) {
203-
init(width, height, RGB, 1);
204+
init(width, height, RGB, getDisplayDPI());
204205

205206
// toxi: is it maybe better to init the image with max alpha enabled?
206207
//for(int i=0; i<pixels.length; i++) pixels[i]=0xffffffff;
@@ -218,7 +219,7 @@ public PImage(int width, int height) {
218219
* @param format Either RGB, ARGB, ALPHA (grayscale alpha channel)
219220
*/
220221
public PImage(int width, int height, int format) {
221-
init(width, height, format, 1);
222+
init(width, height, format, getDisplayDPI());
222223
}
223224

224225

@@ -231,7 +232,7 @@ public PImage(int width, int height, int format, int factor) {
231232
* Do not remove, see notes in the other variant.
232233
*/
233234
public void init(int width, int height, int format) { // ignore
234-
init(width, height, format, 1);
235+
init(width, height, format, getDisplayDPI());
235236
}
236237

237238

@@ -275,6 +276,15 @@ private void init(int width, int height, int format, int factor,
275276
this.pixels = pixels;
276277
}
277278

279+
/*
280+
This method computes the current display's DPI, in order to set the default pixel density to the display's density
281+
(ACHIEVE HIGH-DPI BY DEFAULT)
282+
Change access modifier as needed.
283+
*/
284+
private int getDisplayDPI() {
285+
int dpi = Toolkit.getDefaultToolkit().getScreenResolution();
286+
return dpi > 0 ? dpi : 1; // Fallback to 1 if DPI cannot be determined
287+
}
278288

279289
/**
280290
* Check the alpha on an image, using a really primitive loop.

0 commit comments

Comments
 (0)