Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Directly convert BufferedImage in a File object [duplicate]

Tags:

java

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.

like image 780
user2752929 Avatar asked Oct 21 '22 14:10

user2752929


1 Answers

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

Is this what you are looking for?

like image 194
Jasin Ali Avatar answered Oct 23 '22 04:10

Jasin Ali