How to retrieve graphic card information on Java?
Asked Answered
N

2

8

Is there any possible way to retrieve information of my graphic card adapter using Java API?

I know that DirectX can easily do it, however, I just wonder if Java can do this...?

Like picture below.. DirectX finds out GPU adapter integrated to my hardware, and a list of its supporting resolutions.

My problem is, is there an API that Java would do this kind of thing? I really wonder if Java is able to get information regarding to Video Card.

enter image description here

Thank you.

Nadianadine answered 22/8, 2013 at 11:26 Comment(0)
F
9

As @Sergey K. said in his answer there are several ways to do this. One of these is using dxdiag tool (obviously it will only work on Windows) particularly dxdiag /t variant that will redirect the output to a given file. Then you can process that file to get required info:

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();
    }

}

Generated file will look like this:

enter image description here

And output will look like this:

-- Executing dxdiag command --
-- Printing ./foo.txt info --
Card name: Intel(R) HD Graphics Family
Current Mode: 1366 x 768 (32 bit) (60Hz)

Flax answered 22/8, 2013 at 12:51 Comment(0)
T
3

There are several ways you can do this in Java. But all of them end up using DirectX/OpenGL/C++/WinAPI/whatever as their back-end.

You will need Java bindings for either of this API. Or you can write your code in C/C++ and use it via JNI.

Theresiatheresina answered 22/8, 2013 at 11:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.