How to convert BufferedImage to InputStream? [duplicate]
问题 This question already has answers here : How to get an InputStream from a BufferedImage? (3 answers) Closed 2 months ago . I am uploading images using servlet. To perform resize operations i am converting InputStream to BufferedImage. Now i want to save it in mongoDB. Since, i am new to mongoDB as far as i know, GridFS takes InputStream. So, is there any way to convert BufferedImage to InputStream? 回答1: You need to save the BufferedImage to a ByteArrayOutputStream using the ImageIO class,