how to convert image to byte array in java? [duplicate]
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 IOException { // open image File imgPath = new File(ImageName); BufferedImage bufferedImage = ImageIO.read(imgPath); // get DataBufferBytes from Raster WritableRaster raster = bufferedImage .getRaster(); DataBufferByte data = (DataBufferByte) raster.getDataBuffer(); return ( data.getData() );}
now you can process these bytes by hiding text in lsb for example, or process it the way you want.