Question

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 = ...;
Was it helpful?

Solution

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...

OTHER TIPS

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.

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

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.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top