知識點介紹
JComponent提供了兩個方法,print和printall可以將組件使用Graphics圖形環(huán)境進行繪制,即將組件本身的內容都繪制到Graphics上,我們如果想要將組件保存成圖片的話,只需要創(chuàng)建一個image對象,然后將其Graphics對象傳遞進去即可,如下所示
BufferedImage image = new BufferedImage(imgW + xgap * 2, imgH + ygap * 2, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = (Graphics2D) image.getGraphics();
component.print(g);

下載鏈接
by zhangtao
2009.6.7