How to get graphics card info in Java?

Is there any possible way to get information about my graphics card adapter using the Java API?

I know that DirectX can easily do this, but I'm just wondering if Java can do this ...?

As shown below. DirectX discovers the GPU adapter integrated into my hardware and a list of its supporting permissions.

My problem is, is there an API that Java will do such things? I'm really wondering if Java can get information about the graphics card.

enter image description here

Thanks.

+6
source share
2 answers

As @Sergey K. said, there are several ways to do this in his answer. One of them uses the dxdiag tool (obviously, it will work only on Windows), in particular, the dxdiag /t option, which redirects the output to this file. Then you can process this file to get the necessary information:

 public static void main(String[] args) { try { String filePath = "./foo.txt"; // Use "dxdiag /t" variant to redirect output to a given file ProcessBuilder pb = new ProcessBuilder("cmd.exe","/c","dxdiag","/t",filePath); System.out.println("-- Executing dxdiag command --"); Process p = pb.start(); p.waitFor(); BufferedReader br = new BufferedReader(new FileReader(filePath)); String line; System.out.println(String.format("-- Printing %1$1s info --",filePath)); while((line = br.readLine()) != null){ if(line.trim().startsWith("Card name:") || line.trim().startsWith("Current Mode:")){ System.out.println(line.trim()); } } } catch (IOException | InterruptedException ex) { ex.printStackTrace(); } } 

The generated file will look like this:

enter image description here

And the result will look like this:

- Running the dxdiag command -
- Printing. /foo.txt info -
Card Name: Intel (R) HD Product Family

Current mode: 1366 x 768 (32 bit) (60 Hz)

+8
source

There are several ways to do this in Java. But they all end up using DirectX / OpenGL / C ++ / WinAPI / as their back-end.

You will need Java bindings for any of these APIs. Or you can write your code in C / C ++ and use it through JNI.

+3
source

Source: https://habr.com/ru/post/952276/


All Articles