How to store a byte array as an image file on disk?

前端 未结 3 1109
广开言路
广开言路 2021-02-20 09:08

I have a byte array representation of a Image. How to save it on disk as an image file.

I have already done this

OutputStream out = new FileOutputStream(         


        
3条回答
  •  感情败类
    2021-02-20 09:49

    Other than failing to use a try/finally block (at least in the code you've shown) that should be fine. (You don't need to flush an output stream if you're closing it, by the way.)

    As it's not working, that suggests byteArray doesn't actually contain a JPEG-encoded image. How have you created byteArray to start with? If it's a "raw" representation, you'll probably want to encode it, e.g. using the javax.imageio package.

提交回复
热议问题