5

I saw many examples on the internet on how to convert a File into a BufferedImage, but I need to make a counter conversion.

I've tried some ways, but all are quite 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 don't need write a FileItem, but the BufferedImage that I have processed.

user2752929
  • 311
  • 2
  • 4
  • 14

1 Answers1

3
File outputfile = new File("image.jpg");
ImageIO.write(bufferedImage, "jpg", outputfile);

Is this what you are looking for?

Jasin Ali
  • 66
  • 3