How to remove the title bar from a JFrame screenshot?

跟風遠走 提交于 2019-12-01 08:12:49

问题


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

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?


回答1:


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.



来源:https://stackoverflow.com/questions/4515902/how-to-remove-the-title-bar-from-a-jframe-screenshot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!