How to get the screen DPI in java? -
i developing app need screen dpi.. checked few forums , got code snippet goes follows:
dimension screen = java.awt.toolkit.getdefaulttoolkit().getscreensize(); system.out.println("screen width: "+screen.getwidth()); system.out.println("screen height: "+screen.getheight()); int pixelperinch=java.awt.toolkit.getdefaulttoolkit().getscreenresolution(); system.out.println("pixelperinch: "+pixelperinch); double height=screen.getheight()/pixelperinch; double width=screen.getwidth()/pixelperinch; double x=math.pow(height,2); double y=math.pow(width,2);
but whatever value of screen resolution, pixelperinch
value remains same @ 96. problem code??
i got swt
code same thing goes follows:
import org.eclipse.swt.graphics.device; import org.eclipse.swt.widgets.display; import org.eclipse.swt.widgets.shell; public class mainclass { public void run() { display display = new display(); shell shell = new shell(display); shell.settext("display device"); createcontents(shell); shell.pack(); shell.open(); while (!shell.isdisposed()) { if (!display.readanddispatch()) { display.sleep(); } } display.dispose(); } private void createcontents(shell shell) { device device = shell.getdisplay(); system.out.println("getbounds(): "+ device.getbounds()); system.out.println("getclientarea(): "+device.getclientarea()); system.out.println("getdepth(): "+device.getdepth()); system.out.println("getdpi(): "+device.getdpi()); device.setwarnings(true); system.out.println("warnings supported: "+device.getwarnings()); } public static void main(string[] args) { new mainclass().run(); }
but again here whatever screen resolution, getdpi()
returns same value of 96.. going wrong?? code wrong or interpreting in wrong way??
the problem no one, not os, knows exact physical dimensions of screen. you'd need know in order calculate ppi.
there's display setting in control panel user can manually specify ppi , default it's set 96.
Comments
Post a Comment