w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
JPanel Snapshot and save the image in a file.It shows black image.what to do?

You are creating an empty BufferedImage, to paint the Jpanel on it use:

  try {
        BufferedImage image = new BufferedImage(mypanel.getWidth(),
                mypanel.getHeight(), BufferedImage.TYPE_4BYTE_ABGR);
        Graphics g = image.getGraphics();
        mypanel.printAll(g);
        g.dispose();
        ImageIO.write(image, "png", new File("img.png"));
    } catch (Exception e) {
        e.printStackTrace();
    }




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.