有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

C++如何在java上检索图形卡信息?

是否有任何可能的方法使用Java API检索图形卡适配器的信息

我知道DirectX可以很容易地做到这一点,但是,我只是想知道Java是否可以做到这一点

如下图所示。。DirectX找到了集成到我的硬件中的GPU适配器及其支持的解决方案列表

我的问题是,有没有一个API可以让Java做这种事情? 我真的很想知道Java是否能够获得有关视频卡的信息

enter image description here

多谢各位


共 (2) 个答案

  1. # 1 楼答案

    正如@Sergey K.在他的回答中所说,有几种方法可以做到这一点。其中之一是使用dxdiag工具(显然它只在Windows上工作),尤其是将输出重定向到给定文件的dxdiag /t变量。然后,您可以处理该文件以获取所需信息:

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

    生成的文件如下所示:

    enter image description here

    输出将如下所示:

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

  2. # 2 楼答案

    在Java中有几种方法可以做到这一点。但它们最终都使用DirectX/OpenGL/C++/WinAPI/任何东西作为后端

    这两种API都需要Java绑定。或者您可以用C/C++编写代码,并通过JNI使用它