0

android code Error :

byte[] decodedString = Base64.decode(""aHR0cHM6Ly9ldGlja2V0LmlwZWt0ci5jb20vd3Nib3MzL0xvZ29WZXIuQXNweD9mbnVtPTI2NQ=="", Base64.DEFAULT);
Bitmap base64Bitmap = BitmapFactory.decodeByteArray(decodedString, 0,
                    decodedString.length);
Log.d("img", String.valueOf(base64Bitmap));
imagview.setImageBitmap(base64Bitmap);

logcat Message

SkImageDecoder::Factory returned null
2
  • stackoverflow.com/questions/14681643/… Commented Feb 9, 2016 at 10:25
  • Load using Picasso.with(context).load("i.imgur.com/DvpvklR.png").into(imageView); by adding dependency in project. If you need to do so and required more info revert me. Commented Feb 9, 2016 at 10:28

3 Answers 3

2

Your base64 string is corrupted.

Check it via below link:

http://codebeautify.org/base64-to-image-converter

Please try to decode some different string and then check it.

or try below code :

 byte[] encodeByte = Base64.decode("aHR0cHM6Ly9ldGlja2V0LmlwZWt0ci5jb20vd3Nib3MzL0xvZ29WZXIuQXNweD9mbnVtPTI2NQ", Base64.DEFAULT);
            Bitmap bitmap = BitmapFactory.decodeByteArray(encodeByte, 0,
                    encodeByte.length);
            return bitmap;

If still it won't work try Base64.NOWRAP instead of Base64.DEFAULT.

Sign up to request clarification or add additional context in comments.

Comments

0

Try this

ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this).build();
    ImageLoader.getInstance().init(config);
    ImageLoader imageLoader = ImageLoader.getInstance();

    ImageView imageView = (ImageView) this.findViewById(R.id.imageView);
    try {
        url = decodeBase64String(base64String);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    imageLoader.displayImage(url, imageView);
String decodeBase64String(String encodedString) throws   UnsupportedEncodingException {
    byte[] data = Base64.decode(encodedString, Base64.DEFAULT);
    return new String(data, "UTF-8");
}

set dependency -compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'

Comments

0

Check this function:

    public Bitmap StringToBitMap(String encodedString) {
    try {
        byte[] encodeByte = Base64.decode(encodedString, Base64.DEFAULT);
        Bitmap bitmap = BitmapFactory.decodeByteArray(encodeByte, 0,
                encodeByte.length);
        return bitmap;
    } catch (Exception e) {
        e.getMessage();
        return null;
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.