相关疑难解决方法(0)

如何用Java"正确"检测显示的DPI?

我有以下应用程序绘制规则:

public class Rule extends JComponent
{
  public static final long serialVersionUID=26362862L;
//  public static final int INCH=Toolkit.getDefaultToolkit().getScreenResolution();
  public static final int INCH=(int)(Toolkit.getDefaultToolkit().getScreenResolution()*1.15);  // Auto adjust this 1.15 ?
  public static final int HORIZONTAL=0;
  public static final int VERTICAL=1;
  public static final int SIZE=35;
  public int orientation;
  public boolean isMetric;
  private int increment;
  private int units;
//  private Color rule_color=new Color(0,135,235);
  private Color rule_color=new Color(120,170,230);
  static JFrame frame=new JFrame("Rule");
  static Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize();  // 1600 x 1200  ,  1024 x 768 …
Run Code Online (Sandbox Code Playgroud)

java dpi detect

13
推荐指数
1
解决办法
9238
查看次数

如何在java中获取屏幕DPI?

我正在开发一个应用程序,我需要屏幕DPI ..我检查了几个论坛,并获得了一个代码片段,如下所示:

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); 
Run Code Online (Sandbox Code Playgroud)

但无论屏幕分辨率的pixelPerInch值是多少,96 的值都保持不变.代码有什么问题?

我得到了另一个swt相同的代码,如下所示:

  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(); …
Run Code Online (Sandbox Code Playgroud)

java screen-resolution

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

java ×2

detect ×1

dpi ×1

screen-resolution ×1