As you can see using the link that, Picasso has only 3 options to load an image. My question is how to load an image if you have a base64 string parsed from JSON response from an api?
Asked
Active
Viewed 5,366 times
1
-
refer https://stackoverflow.com/questions/27374840/download-base64-image-on-a-protected-site-using-picasso/42852617#42852617 – sasikumar Sep 03 '18 at 09:32
-
Decode base64 string to normal string and load image – Manohar Sep 03 '18 at 09:32
-
see this link--- https://stackoverflow.com/questions/15683032/android-convert-base64-encoded-string-into-image-view – Bunny Sep 03 '18 at 09:34
-
I worked both with Glide and with Picasso. Glide makes it a lot easier to work with base64 strings and bitmaps. If it is possible you could switch to Glide? – 476rick Sep 03 '18 at 11:11
1 Answers
3
There are no additional methods to do this process in Picasso, you can use the native Java method to convert Base64 text to bytes array then simply get the job done.
You can get the Bitmap image so you can run Picasso using Bitmap as well.
The Base64 text should be formatted as: data:image/png;base64,iV....
String base64Image = base64Text.split(",")[1];
byte[] imageAsBytes = Base64.decode(base64Image.getBytes(), Base64.DEFAULT);
img.setImageBitmap(BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length));

Googlian
- 6,077
- 3
- 38
- 44