Full screen capture of a DirectX program in java (Javacv ?)

匿名 (未验证) 提交于 2019-12-03 08:48:34

问题:

[For Windows] I know it is possible to capture screen of a DirectX program running under C# language, but do you know some sample code for Java?

I am actually facing this same problem than this Take screen shots inside of full screen applications with java?. Robot class didn't helped and neither worked.

But yet I didn't found any sample of java code on the internet concerning this. Thanks for any help you could provide on this topic.

回答1:

Since I worked on it more, see also:

import java.awt.*; import java.awt.datatransfer.*; import java.awt.event.KeyEvent; import java.awt.image.BufferedImage; import javax.swing.*;  import javax.imageio.ImageIO; import java.io.File;  public class ClipboardScreenshot {      public static void main(String[] args) throws Exception {         // get the screenshot         Robot robot = new Robot();         robot.keyPress(KeyEvent.VK_PRINTSCREEN);         robot.delay(40);         robot.keyRelease(KeyEvent.VK_PRINTSCREEN);         robot.delay(404);          Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();         DataFlavor[] flavors = cb.getAvailableDataFlavors();         System.out.println("After: ");         for (DataFlavor flavor : flavors) {             System.out.println(flavor);             if (flavor.toString().indexOf("java.awt.Image")>0) {                 Object o = cb.getData(flavor);                 Image i = (Image)o;                 // ImageIO will not write an Image                 // It will write a BufferedImage (a type of RenderedImage)                 BufferedImage bi = new BufferedImage(                         i.getWidth(null),                         i.getHeight(null),                         BufferedImage.TYPE_INT_RGB);                 Graphics2D g = bi.createGraphics();                 g.drawImage(i, 0, 0, null);                 g.dispose();                  JScrollPane sp = new JScrollPane(new JLabel(new ImageIcon(bi)));                 sp.setPreferredSize(new Dimension(800,600));                 JOptionPane.showMessageDialog(null, sp);                 File f = new File(                         System.getProperty("user.home") +                          File.separator +                          "the.png");                 ImageIO.write(bi, "png", f);             }         }     } } 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!