gpt4 book ai didi

java - Java 中 DirectX 程序的全屏捕获(Javacv?)

转载 作者:搜寻专家 更新时间:2023-10-31 20:29:48 25 4
gpt4 key购买 nike

[对于 Windows]我知道可以捕获在 C# 语言下运行的 DirectX 程序的屏幕,但是您知道一些 Java 示例代码吗?

我实际上面临着与这个相同的问题 Take screen shots inside of full screen applications with java? .机器人类(class)没有帮助,也没有用。

但是我还没有在互联网上找到任何与此相关的 Java 代码示例。感谢您就此主题提供的任何帮助。

最佳答案

由于我在这方面做了更多工作,另请参阅:

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 - Java 中 DirectX 程序的全屏捕获(Javacv?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12262448/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com