How to save a BufferedImage as a File

后端 未结 6 1275
名媛妹妹
名媛妹妹 2020-11-29 20:16

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

6条回答
  •  天涯浪人
    2020-11-29 20:39

    You can save a BufferedImage object using write method of the javax.imageio.ImageIO class. The signature of the method is like this:

    public static boolean write(RenderedImage im, String formatName, File output) throws IOException
    

    Here im is the RenderedImage to be written, formatName is the String containing the informal name of the format (e.g. png) and output is the file object to be written to. An example usage of the method for PNG file format is shown below:

    ImageIO.write(image, "png", file);
    

提交回复
热议问题