how to convert image to byte array in java? [duplicate]
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This question already has an answer here: File to byte[] in Java 20 answers I want to convert an image to byte array and vice versa. Here, the user will enter the name of the image ( .jpg ) and program will read it from the file and will convert it to a byte array. 回答1: BufferedImage consists of two main classes: Raster & ColorModel . Raster itself consists of two classes, DataBufferByte for image content while the other for pixel color. if you want the data from DataBufferByte, use: public byte[] extractBytes (String ImageName) throws