How to convert buffered image to image and vice-versa?

后端 未结 6 598

Actually i am working on a image editing software and now i want to convert the buffered-image i.e :

  BufferedImage buffer = ImageIO.read(new File(file));
<         


        
6条回答
  •  清歌不尽
    2020-12-05 14:36

    You can try saving (or writing) the Buffered Image with the changes you made and then opening it as an Image.

    EDIT:

    try {
        // Retrieve Image
        BufferedImage buffer = ImageIO.read(new File("old.png"));;
        // Here you can rotate your image as you want (making your magic)
        File outputfile = new File("saved.png");
        ImageIO.write(buffer, "png", outputfile); // Write the Buffered Image into an output file
        Image image  = ImageIO.read(new File("saved.png")); // Opening again as an Image
    } catch (IOException e) {
        ...
    }
    

提交回复
热议问题