I am selecting an image using Jsoup parser
Elements images = document.select("img");
String src = images.attr("src");
then using this code to get rid off data:image/jpg;base64
pureImageSrc = imageSrc.substring(imageSrc.indexOf(",") + 1);
Now I have correct base 64 string (i guess) which starts and ends like
/9j/4AAQSkZJRgABAQEASABIAAD/4Vl6RXhpZgAAT...............lbRIluL+9/56L+VFOoqhH/2Q==
finally, I am decoding it and setting inside an image view
byte[] decodedString = Base64.decode(pureImageSrc, Base64.URL_SAFE);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
imageView.setImageBitmap(decodedByte);
But getting this exception: java.lang.IllegalArgumentException: bad base-64
What's missing in this?
You are decoding with the flag Base64.URL_SAFE
which uses -
and _
in place of +
and /
, your base64 string includes /
. Try changing the flag to Base64.DEFAULT
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