获取 Applet 的屏幕截图?
给定一个 Applet 对象,是否可以以编程方式获取 applet 窗口的“屏幕截图”(表示为 BufferedImage)?
JApplet applet = this;
// ... code here ...
BufferedImage screenshotOfApplet = ...;
Given an Applet object, is it possible to programatically obtain a "screen shot" of the applet window (represented as say a BufferedImage)?
JApplet applet = this;
// ... code here ...
BufferedImage screenshotOfApplet = ...;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
至少如果您只使用 Swing 组件,我想可以创建一个与小程序大小相同的 BufferedImage,并使用可以从 BufferedImage#getGraphics() 获取的 Graphics 对象调用小程序的绘制方法。我这里没有模板代码来测试它是否真的有效,但我想值得一试。
At least if you're only using Swing components, I suppose it would be possible to create a BufferedImage of the same size as the applet and call the applet's paint method with the Graphics object you can get from BufferedImage#getGraphics(). I have no template code here to test if it actually works, but I guess it's worth a try.
您可以使用Robot.createScreenCapture(矩形边界) - 但是,必须对该小程序进行签名才能在部署后使其正常工作。
评论后 -
如果您只想要小程序组件 -
您可以创建一个 BufferedImage 并对其进行绘制 - 像这样:
我不确定这是否需要对小程序进行签名...
You could use
Robot.createScreenCapture(Rectangle bounds)
- however, the applet would have to be signed to allow this to work once deployed.After comments -
If you just want the applet component -
You can create a BufferedImage and paint to it - something like this:
I'm not sure if this would require the applet to be signed or not...
屏幕图像。必须承认我以前从未在 JApplet 上尝试过它,但它在 JFrames 和 JDialogs 上运行得很好。
Screen Image. Must admit I've never tried it on a JApplet before, but it works fine on JFrames and JDialogs.
我想你想要
java.awt.image.PixelGrabber
。 (IIRC,Java 图形性能从 1.1 到 1.2 大幅下降的原因是,尽管我可能是错的。)I think you want
java.awt.image.PixelGrabber
. (IIRC, that was behind the massive slowdown is Java graphics performance from 1.1 to 1.2, although I might be wrong.)