How to get the screen DPI in java?

前端 未结 2 2096
离开以前
离开以前 2020-12-03 23:06

I am developing an app for which I need the screen DPI.. I checked a few forums and got a code snippet which goes as follows:

Dimension screen = java.awt.Too         


        
2条回答
  •  执念已碎
    2020-12-03 23:17

    this code works for me on win10

    import javafx.stage.Screen 
    
    double getScaleFactor() {
            double trueHorizontalLines = Toolkit.getDefaultToolkit().getScreenSize().getHeight();
            double scaledHorizontalLines = Screen.getPrimary().getBounds().getHeight();
            double dpiScaleFactor = trueHorizontalLines / scaledHorizontalLines;
            return dpiScaleFactor;
        }
    

    it uses some awt apis though

提交回复
热议问题