Swing


天行健 君子以自强不息

posts - 69, comments - 215, trackbacks - 0, articles - 16
   :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

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

Posted on 2009-06-07 00:44 zht 阅读(1674) 评论(0)  编辑  收藏 所属分类: Swing

知识点介绍
        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