2013-08-22 24 views
6

是否有任何可能的方式來檢索我的圖形卡適配器使用Java API的信息?如何檢索Java上的圖形卡信息?

我知道DirectX可以輕鬆地做到這一點,但是,我只是想知道Java是否可以做到這一點...?

如下圖所示.. DirectX找出集成到我的硬件的GPU適配器以及其支持分辨率的列表。

我的問題是,是否有Java的API會做這種事情? 我真的不知道Java是否能夠獲得有關視頻卡的信息。

enter image description here

謝謝。

回答

8

正如@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

和輸出看起來就像這樣:

- 執行dxdiag命令 -
- 打印./foo.txt信息 -
卡名稱:英特爾(R)HD G raphics家庭
電流模式:1366 x 768(32位)(60Hz)

3

有幾種方法可以在Java中執行此操作。但他們最終都使用DirectX/OpenGL/C++/WinAPI /作爲其後端。

您將需要此API的Java綁定。或者你可以用C/C++編寫代碼並通過JNI使用它。