Convert BufferedImage to File?

1

I need to convert a BufferedImage to a File . I tried the following, but it did not work:

File file = null;
ImageIO.write(image, "jpg", file);

image is of type BufferedImage .

That was the error:

  

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: output == null!     at javax.imageio.ImageIO.write (Unknown Source) *

    
asked by anonymous 03.12.2015 / 21:10

1 answer

2

The problem was that you instantiated your File as null .

File file  = new File("image.jpg");
ImageIO.write(image, "jpg", file );

You must specify the path of the image.

    
03.12.2015 / 21:20