Java框架屏幕截图显示重新粉刷

发布于 2025-01-27 15:55:29 字数 493 浏览 2 评论 0原文

我正在执行应用程序的jframe的屏幕截图,但通常会出现绘图伪影,例如在左上角的框架中的图像(不是通常的位置),因为我相信它在重新粉刷过程中抓住它。

有什么办法吗?我尝试在A Repaver()希望它能保持完成后添加1/2秒延迟,但没有起作用(尽管出现问题的频率较低)。我认为合适的框架重新粉刷上有多个控件。我还设置了一个标志,以防止随时间延迟进行程序化重新粉刷,但是问题仍然蔓延。

我正在为屏幕截图使用以下代码:

BufferedImage img = new BufferedImage(this.getWidth(),this.getHeight(),BufferedImage.TYPE_INT_RGB);
this.paint(img.getGraphics());
File outputfile = new File(saveImageName);
ImageIO.write(img, ext, outputfile);

I'm performing screen shots of my app's JFrame, but often a drawing artefact shows up, such as an image in my frame in the upper-left corner (not where it normally is), because I believe it's catching it during a repaint.

Any way around this? I've tried adding a 1/2 second delay after a repaint() hoping it would stay finished, but didn't work (though problems occurred less often). I've got multiple controls on the frame repainting as they see fit. I've also set a flag to prevent programmatic repainting with the time delay, but problems still creep in.

I'm using the following code for the screenshot:

BufferedImage img = new BufferedImage(this.getWidth(),this.getHeight(),BufferedImage.TYPE_INT_RGB);
this.paint(img.getGraphics());
File outputfile = new File(saveImageName);
ImageIO.write(img, ext, outputfile);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文