1
如何注入Java applet的getGraphics()方法?
首先我想說的是,這是我最喜歡的Java幫助站點。 (和其他語言)
現在我的問題是,我想截取一個Java小程序。
我已通過java.net.URLClassLoader加載小程序並將其添加到我的JFrame中。
我可以在我的JFrame中看到它,但我想將它渲染到截圖。
NORMAL小程序的解決方案在此處提及:Taking a "screenshot" of a java applet
但是,此Applet不使用paint或update方法,而是使用getGraphics()方法。
我已經注入了AppletStub,所以小程序認爲他在自己的網站上。
但是,我怎樣才能注入applet的getGraphics()方法來呈現它的截圖?
順便說一句,這是我的代碼:
@Override
public void actionPerformed(final ActionEvent e) {
final String s = e.getActionCommand();
if (s.equals("Screenshot")) {
final BufferedImage offScreen = new BufferedImage(800, 600, BufferedImage.TYPE_INT_RGB);
Loader.getApplet().update(offScreen.createGraphics());
try {
ImageIO.write(offScreen, "PNG", new File("C:/Users/Mitchell/Pictures/screenshot.png"));
} catch (Exception ex) { }
}
}
所有它創建一個黑色的800x600的PNG圖片(空的BufferedImage)。
所以你的意思是:public class GraphicsInjector extends Applet? – BlazeByte
我的意思是'GraphicsInjector extends X',其中'X'是你正在嘗試使用的applet。 –
我已經想出了,但Applet是一個變量...:P – BlazeByte