Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

conversion of byte array to image

Tags:

android

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.

like image 307
Geethu Avatar asked Jan 08 '13 05:01

Geethu


People also ask

What is byte array image?

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.

How can I get bytes of an image?

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.

How do you check if a byte array is a valid image java?

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.

What is byte array example?

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.


1 Answers

Hope this code will help you:

byte[] data = item1.getBytes();
Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
imageview.setImageBitmap(bmp);
like image 170
Mohan Avatar answered Sep 24 '22 03:09

Mohan