I am trying to convert byte array into image in android.
I have a ArrayList<Byte> arrays; that contains all byte arrays that I want to convert.
Now at
byt = (byte[]) arrays.get(0);
its giving me Cannot cast from Byte to byte[] java exception.
byte[] byt;
byt = new byte[4096];
byt = (byte[]) arrays.get(0) ;
BufferedImage bImageFromConvert = null;
InputStream in = new ByteArrayInputStream(byt);
try {
bImageFromConvert = ImageIO.read(in);
SaveImages();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
How can I solve this?
The ArrayList doesn't contain Byte[] or byte[] values, however the list itself can be converted to a byte array as it contains individual byte values
byte[] bytes = new byte[array.size()];
for (int i = 0; i < array.size(); i++) {
bytes[i] = array.get(i);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With