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
Rohit5k2
  • 17,948
  • 8
  • 45
  • 57
Piyush Amipara
  • 135
  • 1
  • 12
  • http://stackoverflow.com/questions/14681643/image-isnt-creating-using-the-bitmapfactory-decodebytearray – Suhas Bachewar Feb 09 '16 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. – Suhas Bachewar Feb 09 '16 at 10:28

3 Answers3

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.

KishuDroid
  • 5,411
  • 4
  • 30
  • 47
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;
    }
}
Dhruv
  • 1,801
  • 1
  • 15
  • 27
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'

Govind Rakholiya
  • 295
  • 1
  • 3
  • 20