How to convert Java Image into JPEG array of bytes?

China☆狼群 提交于 2019-12-11 14:49:06

问题


Is there a way to convert a Java Image, encode it into JPEG (but not saving it to a file), and store it as an array of bytes? (byte[]) I need the JPEG-encoded image as an array of bytes.


回答1:


ImageIO has a number of methods for reading and writing images.

For writing to array of bytes, you can write to ByteArrayOutputStream. And then call toByteArray[] of the stream object to obtain the byte array.



来源:https://stackoverflow.com/questions/2568150/how-to-convert-java-image-into-jpeg-array-of-bytes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!