I want to convert a byte array to an image ,For that I used the code
final BufferedImage bufferedImage = ImageIO.read(new ByteArrayInputStream(decrpt));
where Decrypt is the byte array,It showing error in ImageIO.I dont know what is that parameter pls help me to sort it out.
Images are binary data - this is easily represented as byte arrays. The image in the sample is stored in the database as a BLOB - not a string or location, that is, it is binary data.
Read the image using the read() method of the ImageIO class. Create a ByteArrayOutputStream object. Write the image to the ByteArrayOutputStream object created above using the write() method of the ImageIO class. Finally convert the contents of the ByteArrayOutputStream to a byte array using the toByteArray() method.
You can try to generate an image from the byte array and check for the ArgumentException if its not. Show activity on this post. Most other types of image files have similar magick numbers. But checking that won't actually tell you if the file is a valid image file.
A byte is 8 bits (binary data). A byte array is an array of bytes (tautology FTW!). You could use a byte array to store a collection of binary data, for example, the contents of a file. The downside to this is that the entire file contents must be loaded into memory.
Hope this code will help you:
byte[] data = item1.getBytes();
Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
imageview.setImageBitmap(bmp);
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