Directly convert BufferedImage to File object

I have seen many examples on the Internet about how to convert a file to BufferedImage, but I need to do a counter conversion.

I tried several ways, but it's pretty complicated.

I wonder if there is a direct way to accomplish this.

I have this in my code:

for (FileItem item : formItems) {
                // processes only fields that are not form fields
                if (!item.isFormField()) {
                    Date date = new Date();
                    String fileName = new File(item.getName()).getName();
                    String filePath = uploadPath + date.getTime() + fileName + ".tmp";
                    File storeFile = new File(filePath);

                    BufferedImage tempImg = ImageIO.read(storeFile);

                    //I make process in the tempImg

                    //I need save it
                    item.write(tempImg);
                }
            }

I do not need to write FileItem, but the BufferedImage that I processed.

+4
source share
1 answer
File outputfile = new File("image.jpg");
ImageIO.write(bufferedImage, "jpg", outputfile);

Is this what you are looking for?

+2
source

Source: https://habr.com/ru/post/1526857/


All Articles