如何将Java Image转换为JPEG字节数组? [英] How to convert Java Image into JPEG array of bytes?
本文介绍了如何将Java Image转换为JPEG字节数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一种方法可以转换Java图像,将其编码为JPEG(但不能将其保存到文件中),并将其存储为字节数组? (byte [])我需要将JPEG编码的图像作为字节数组。
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.
推荐答案
ImageIO
有许多读取和写入图像的方法。
ImageIO
has a number of methods for reading and writing images.
要写入字节数组,可以写入 ByteArrayOutputStream
。然后调用流对象的 toByteArray []
获得字节数组。
For writing to array of bytes, you can write to ByteArrayOutputStream
. And then call toByteArray[]
of the stream object to obtain the byte array.
这篇关于如何将Java Image转换为JPEG字节数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文