2

I need to figure out what the scaling is set to. This answer at Windows scaling gives code in c/c++/c#, but I need it in Java and would much prefer to not have to do JNI. Is there a way to use JNA to get that information?

CamHart
  • 3,825
  • 7
  • 33
  • 69

1 Answers1

6

This appears to do it:

GraphicsConfiguration asdf = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();

AffineTransform asfd2 = asdf.getDefaultTransform();

double scaleX = asfd2.getScaleX();
double scaleY = asfd2.getScaleY();

Forgive the bad variable names. And instead of defaults, you may want to account for multiple displays. But that shows how it can be done.

Samuel Philipp
  • 10,631
  • 12
  • 36
  • 56
CamHart
  • 3,825
  • 7
  • 33
  • 69
  • Thanks a lot. You are a savior. However one thing I would like to point out. In Java 8. Value is always coming as 1.0 Working fine in open jdk 11. – Vaibhav Jain Nov 17 '19 at 11:25