简体   繁体   English

如何从JFrame屏幕截图中删除标题栏?

[英]How to remove the title bar from a JFrame screenshot?

I'm capturing a screenshot image of a JFrame via a "double buffering" approach, per below: 我正在通过“双重缓冲”方法捕获JFrame的屏幕截图,如下所示:

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;     
}

where this extends JFrame. this扩展了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? 在没有为标题栏分配额外空间的情况下,捕获JFrame内容图像的最直接方法是什么?

You should be able to use the Screen Image class. 您应该能够使用Screen Image类。 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. 还是您的基本代码应该起作用,再次将内容窗格(或根窗格)指定为要绘制的组件,而不是框架itelf。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM