如何将图形内容捕获为图像

McG*_*k07 0 java swing video-capture

我有一个透明的 jframe,上面有滚动文本,我需要捕获 jframe,而不是它后面的内容。起初,java.awt.Robot 看起来很有前途,但它不仅仅捕获 jframe 的图形上下文。也许有人知道 API 的一部分可以帮助解决这个问题......

sin*_*a72 5

你可以

  1. 使用 JFrame 的大小创建 BufferedImage
  2. 使用 BufferedImage 的图形调用 JFrame 的 print() 方法

代码:

BufferedImage image = new BufferedImage(frame.getWidth(), frame.getHeight(), BufferedImage.TYPE_INT_RGB);
frame.print(image.getGraphics());
Run Code Online (Sandbox Code Playgroud)