Android - Convert String To Byte[]
I want to convert the string of 'icon' to byte array and than to convert it to Bitmap. The problem is the image in the emulator is not displaying. I suppose I'm not doing right but
Solution 1:
From the string icon
it seems you have converted your image to string by using Base64. So you have to convert it back to bytes using Base64 itself
// Receiving sidebyte[] data = Base64.decode(iconString, Base64.DEFAULT);
Hope this helps...
Solution 2:
To decode your base64string
to byte[]
:
byte[] imgBytes = Base64.decode(strBase64.getBytes());
To convert your byte[]
to Bitmap
:
Bitmapbitmap= BitmapFactory.decodeByteArray(imgBytes, 0, imgBytes.length)
Now use your bitmap
with your images's setImageBitmap method to show the output. For example:
icon.setImageBitmap(bitmap);
Solution 3:
Your icon is Base64 encoded, use Base64 class to decode it.
Post a Comment for "Android - Convert String To Byte[]"