How to save a BufferedImage as a File

Ankur picture Ankur · Oct 1, 2012 · Viewed 210.4k times · Source

I am using the imgscalr Java library to resize an image .

The result of a resize() method call is a BufferedImage object. I now want to save this as a file (usually .jpg).

How can I do that? I want to go from BufferedImage -> File but perhaps this is not the correct approach?

Answer

Werner Kvalem Vesterås picture Werner Kvalem Vesterås · Oct 1, 2012
File outputfile = new File("image.jpg");
ImageIO.write(bufferedImage, "jpg", outputfile);