Swing DayDayUP之一:JComponent组件保存为图片

知识点介绍
        JComponent提供了两个方法,print和printall可以将组件使用Graphics图形环境进行绘制,即将组件本身的内容都绘制到Graphics上,我们如果想要将组件保存成图片的话,只需要创建一个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

你可能感兴趣的:(Swing DayDayUP之一:JComponent组件保存为图片)