Processing for Android

EN ES

displayDensity

The logical density of the display from getDisplayMetrics().density from the Android API. According to Android's documentation: This is a scaling factor for the Density Independent Pixel unit, where one DIP is one pixel on an approximately 160 dpi screen (for example a 240x320, 1.5" screen), providing the baseline of the system's display. Thus on a 160dpi screen this density value will be 1; on a 120 dpi screen it would be .75; etc.

This factor can be used to scale the graphical elements in a sketch, like text and shapes, to present approximately the same size independently of the screen's dpi:

 void setup() {   PFont font = createFont("SansSerif", 24 * displayDensity);   textFont(font);   textAlign(CENTER, CENTER); } void draw() {   text("hello", width/2, height/2); }