将 JPanel 转换为 png 或其他图像文件
我有一个由很多 JLabels 组成的 JPanel。所以根本没有油漆,只有具有不同背景颜色等的 JLabel。 JPanel 可见。
如何将此 JPanel 转换为图像文件?该图像文件将是 JPanel 的图片,与屏幕上显示的一模一样。
(理想情况下,程序会创建一个 .png,并将其保存到程序所在的同一文件夹中,甚至保存到用户选择的不同文件夹中。)
任何建议将不胜感激。谢谢!
---- 又是 Cherie,未注册,所以我无法返回我的帐户以选择 stas 的答案作为答案。这就是为什么我不回复...无论如何,谢谢你的帮助。切丽
I have a JPanel that consists of a lot of JLabels. So there is no paint at all, just JLabels with different background colors and such. The JPanel is visible.
How can I convert this JPanel to an image file? The image file would be a picture of the JPanel exactly as it appears on the screen.
(Ideally, the program would create a .png, and save it to the same folder that the program is in or even a different folder chosen by the user.)
Any advice would be appreciated. Thanks!
---- It's Cherie again, unregistered so I couldn't get back into my account to choose stas's answer as the answer. This is why I'm not replying... anyway, thank you for your help. Cherie
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
屏幕图像将选择创建图像的最佳方式。
Screen Image will choose the best way to create the image.
像这样:
您创建一个这样的文件:
如果我回答了您的问题,请选择我的答案是正确的:)
like this:
You create a file like this:
please select my answer as correct if i answered your question :)
java.awt.Robot 类可以获取屏幕转储,然后您可以将其放在以后需要的地方。
The java.awt.Robot classes can take a screen dump which you can then put where you need it for later.