在Java中全屏捕获DirectX程序(Javacv?) [英] Full screen capture of a DirectX program in java (Javacv ?)
本文介绍了在Java中全屏捕获DirectX程序(Javacv?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
[对于Windows]
我知道可以捕获在C#语言下运行的DirectX程序的屏幕,但你知道一些Java的示例代码吗?
[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?
我实际上遇到的问题与此相同使用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.
但是我没有在互联网上找到任何关于此问题的java代码示例。
感谢您提供有关此主题的任何帮助。
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.
推荐答案
由于我的工作更多,请参阅:
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);
}
}
}
}
这篇关于在Java中全屏捕获DirectX程序(Javacv?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文