首页 > 解决方案 > 有没有办法在透明背景而不是 JFrame 本身上生成 JFrame 组件的图片?

问题描述

我有一种方法,它采用文件路径和文件名来保存当前表单的图片。但问题是,我希望它只保存框架的组件而不是框架背景。我真的是初学者,所以有人可以帮助我吗?

public void save(String imageFile, String path) throws InterruptedException {
        Rectangle r = getBounds();

        try {
            BufferedImage i = new BufferedImage(r.width,r.height,
            BufferedImage.TYPE_INT_RGB);
            Graphics g = i.createGraphics();//getGraphics();
            paintComponents(g);
            ImageIO.write(i, "png", new File(imageFile,path));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

标签: javaswingnetbeans-8paintcomponent

解决方案


推荐阅读