获取 Applet 的屏幕截图?

发布于 2024-08-06 19:38:43 字数 183 浏览 5 评论 0原文

给定一个 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 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

迟月 2024-08-13 19:38:43

至少如果您只使用 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.

七堇年 2024-08-13 19:38:43

您可以使用Robot.createScreenCapture(矩形边界) - 但是,必须对该小程序进行签名才能在部署后使其正常工作。

评论后 -

如果您只想要小程序组件 -

您可以创建一个 BufferedImage 并对其进行绘制 - 像这样:

public static BufferedImage imageFor(Component component) {
    BufferedImage image = new BufferedImage(component.getWidth(), 
            component.getHeight(), BufferedImage.TYPE_INT_RGB);
    Graphics g = image.getGraphics();
    component.paint(g);
    return image;
}

我不确定这是否需要对小程序进行签名...

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:

public static BufferedImage imageFor(Component component) {
    BufferedImage image = new BufferedImage(component.getWidth(), 
            component.getHeight(), BufferedImage.TYPE_INT_RGB);
    Graphics g = image.getGraphics();
    component.paint(g);
    return image;
}

I'm not sure if this would require the applet to be signed or not...

悟红尘 2024-08-13 19:38:43

屏幕图像。必须承认我以前从未在 JApplet 上尝试过它,但它在 JFrames 和 JDialogs 上运行得很好。

Screen Image. Must admit I've never tried it on a JApplet before, but it works fine on JFrames and JDialogs.

温柔戏命师 2024-08-13 19:38:43

我想你想要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.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文