How to remove the title bar from a JFrame screenshot?(如何从 JFrame 屏幕截图中删除标题栏?)
问题描述
我正在通过双缓冲"方法捕获 JFrame 的屏幕截图,如下所示:
I'm capturing a screenshot image of a JFrame via a "double buffering" approach, per below:
public BufferedImage getScreenshot() {
java.awt.Dimension dim = this.getPreferredSize();
BufferedImage image = new BufferedImage(dim.width, dim.height, BufferedImage.TYPE_INT_RGB);
this.paint(image.getGraphics());
return image;
}
this
扩展了 JFrame.我得到的图像在标题栏所在的顶部有一个空白条.在不为标题栏分配额外空间的情况下捕获 JFrame 内容图像的最直接方法是什么?
where this
extends JFrame. The image that I get has a blank strip along the top where the title bar was. What's the most straightforward way to capture an image of the contents of the JFrame without the extra space allocated for the title bar?
推荐答案
你应该可以使用 屏幕图像类.只需将框架的内容窗格(或如果您有菜单,则为根窗格)指定为您想要的图像的组件.
You should be able to use the Screen Image class. Just specify the content pane of the frame (or the root pane if you have a menu) as the component you want the image of.
或者您的基本代码应该可以工作,再次将内容窗格(或根窗格)指定为您要绘制的组件,而不是框架本身.
Or your basic code should work, again just specify the content pane (or root pane) as the component you want to paint, not the frame itelf.
这篇关于如何从 JFrame 屏幕截图中删除标题栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何从 JFrame 屏幕截图中删除标题栏?


基础教程推荐
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01
- Java Swing计时器未清除 2022-01-01
- 大摇大摆的枚举 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- 从 python 访问 JVM 2022-01-01
- 多个组件的复杂布局 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01