当用户在Windows设置上更改屏幕分辨率时,如何使用Java获得正确的DPI显示?

时间:2017-02-01 12:34:17

标签: java windows awt screen-resolution toolkit

为了能够获得dpi值,我正在使用它:

dpi

事先显示设置,当我应用 1366 x 768 作为分辨率值时;

96值返回dpi(这就是我的预期)

然而,当我在设置中更改 800 x 600 作为分辨率值时

96值返回96(该值应低于Sub ReduceFileSize() Dim wB As Workbook Dim wS As Worksheet Set wB = ThisWorkbook For Each wS In wB.Sheets DeleteUnUsed wS Next wS wB.Save End Sub Sub DeleteUnUsed(wS As Worksheet) Dim r As Range Dim LastRow As Double LastRow = LastRow_1(wS) Dim LastCol As Double LastCol = LastCol_1(wS) With wS .Range(LastRow + 1 & ":" & .Rows.Count).EntireRow.Delete .Range(collet(LastCol) & ":" & collet(.Columns.Count)).EntireColumn.Delete End With End Sub Public Function LastRow_1(wS As Worksheet) As Double With wS If Application.WorksheetFunction.CountA(.Cells) <> 0 Then LastRow_1 = .Cells.Find(What:="*", _ After:=.Range("A1"), _ Lookat:=xlPart, _ LookIn:=xlFormulas, _ SearchOrder:=xlByRows, _ SearchDirection:=xlPrevious, _ MatchCase:=False).Row Else LastRow_1 = 1 End If End With End Function Public Function LastCol_1(wS As Worksheet) As Double With wS If Application.WorksheetFunction.CountA(.Cells) <> 0 Then LastCol_1 = .Cells.Find(What:="*", _ After:=.Range("A1"), _ Lookat:=xlPart, _ LookIn:=xlFormulas, _ SearchOrder:=xlByColumns, _ SearchDirection:=xlPrevious, _ MatchCase:=False).Column Else LastCol_1 = 1 End If End With End Function Public Function ColLet(x As Integer) As String With ActiveSheet.Columns(x) ColLet = Left(.Address(False, False), InStr(.Address(False, False), ":") - 1) End With End Function

当我在 mac 计算机中尝试相同的情况时,正确的值即将到来。

我认为来自Windows操作系统的分辨率值存在问题。我测试了 Windows 7 Windows 10

修改:要了解我需要此值的原因,请查看此问题及其answer

1 个答案:

答案 0 :(得分:0)

我认为答案在official documentation

  

指定在屏幕上显示文本和其他项目的大小。    Windows DPI值是介于96和480之间的整数。支持的值   包括96,120和144.默认情况下,Windows使用自动DPI   配置。

这就是为什么它为800 x 600返回96