I have a following binary data (byte array) "The image's binary data received from server" that i receive from my server in String format. How do I convert it back to image in Android.
6
-
possible duplicate of how to convert binary data to image?KTAnj– KTAnj2015-09-25 03:58:31 +00:00Commented Sep 25, 2015 at 3:58
-
@KTAnj nope didnot workJanam Raj Kaji Maharjan– Janam Raj Kaji Maharjan2015-09-25 04:07:57 +00:00Commented Sep 25, 2015 at 4:07
-
don't you have url of the photo that would be way effectivekaran– karan2015-09-25 05:58:02 +00:00Commented Sep 25, 2015 at 5:58
-
@KaranMer I do actually.. I was told that this way it would be faster, so I was trying to learn this methodJanam Raj Kaji Maharjan– Janam Raj Kaji Maharjan2015-09-25 08:36:02 +00:00Commented Sep 25, 2015 at 8:36
-
did u know about libraries like picasso and glide?karan– karan2015-09-25 08:45:20 +00:00Commented Sep 25, 2015 at 8:45
|
Show 1 more comment
1 Answer
You can easily convert your byte data to image by using following code :
byte[] data = "Your byte data";
imageview.setImageBitmap(BitmapFactory.decodeByteArray(data, 0, data.length));
Hope it will solve your problem.
7 Comments
Janam Raj Kaji Maharjan
the binary data is in String format and converting it to byte[] is giving problem
KishuDroid
use this byte[] data = string.getBytes();
Janam Raj Kaji Maharjan
Image This is the data that I have to convert to image. Could you help me recognize the format. Thank you
Janam Raj Kaji Maharjan
leftwritesleft.wordpress.com/2015/09/25/image This should work. Have tried Base64 decoding methods .. but has not worked for me yet. Any help will be appreciated.
KishuDroid
i suggestion for you : instead of getting image like this get url of image.
|