我有以下应用程序绘制规则:
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中获取屏幕大小?
不是屏幕分辨率,屏幕/显示器尺寸(英寸和宽高比).开发的应用程序必须显示某种必须具有相同大小的测试,而不管屏幕大小和宽高比.让我们说我们想要显示一个宽2厘米,高2厘米的矩形,我们希望它对于每种可能类型的显示适配器都是相同的大小.
我正在使用java来获取屏幕的尺寸和分辨率.当我运行以下代码时,我得到下面的输出.
Toolkit toolkit = Toolkit.getDefaultToolkit ();
Dimension dim = toolkit.getScreenSize();
System.out.println("Width of Screen Size is "+dim.width+" pixels");
System.out.println("Height of Screen Size is "+dim.height+" pixels");
int resolution =Toolkit.getDefaultToolkit().getScreenResolution();
System.out.println(resolution);
Run Code Online (Sandbox Code Playgroud)
输出:
Width of Screen Size is 1920 pixels
Height of Screen Size is 1080 pixels
120
Run Code Online (Sandbox Code Playgroud)
现在Javadoc说getScreenResolution以dpi(每英寸点数)返回分辨率.我认为这意味着如果我的图像宽度为600像素,那么屏幕上的图像将为5英寸.当我测量时,它实际上是4英寸宽.告诉我它应该是150 dpi.
我的显示器是一个15.6英寸的显示器,我测量它的宽度为13.6英寸,高度超过7.6英寸.现在我的屏幕宽度显然是1920像素宽,计算到每英寸约141像素.同样1080/7.6计算至每英寸约141个像素.
此网页显示600x600像素的图像.我在屏幕上测量它为4.25",计算到141像素.
为什么getScreenResolution返回120?
如果我误解了这一点,请告诉我.
在加载用户友好的游戏设置时,我遇到了一个问题.
我想做的是:
我试图以可区分的方式加载所有监视器的名称.
我尝试过的:
WMIC:
C:\Users\Matt>wmic
wmic:root\cli>DESKTOPMONITOR
Availability Bandwidth Caption ConfigManagerErrorCode ConfigManagerUserConfig CreationClassName Description DeviceID DisplayType ErrorCleared ErrorDescription InstallDate IsLocked LastErrorCode MonitorManufacturer MonitorType Name PixelsPerXLogicalInch PixelsPerYLogicalInch PNPDeviceID PowerManagementCapabilities PowerManagementSupported ScreenHeight ScreenWidth Status StatusInfo SystemCreationClassName SystemName
8 Generic PnP Monitor 0 FALSE Win32_DesktopMonitor Generic PnP Monitor DesktopMonitor1 (Standard monitor types) Generic PnP Monitor Generic PnP Monitor 96 96 DISPLAY\LGD02DA\4&265EFD6&0&UID67568640 OK Win32_ComputerSystem ALIENWARE
3 Generic PnP Monitor 0 FALSE Win32_DesktopMonitor Generic PnP Monitor DesktopMonitor2 (Standard monitor types) Generic PnP Monitor Generic PnP …Run Code Online (Sandbox Code Playgroud)