1

I receive byte string in response but whenever i trying to convert it in bitmap it giving me null value.I am using below code for converting to bitmap.Anyone Help me?

byte[] decodedString = Base64.decode(strImageid, Base64.NO_WRAP);
        Bitmap decodedByte = BitmapFactory.decodeByteArray( decodedString, 0, decodedString.length);
holder.imageView.setImageBitmap(decodedByte);
DevMobApp
  • 115
  • 1
  • 2
  • 10

2 Answers2

1

it's working fine using glide getting bitmap images.

private void applyProfilePicture(EmployeeViewHolder holder, List<AllRestaurantList> dataList, final int position) {
        if (!TextUtils.isEmpty(dataList.get(position).getImage())) {

            String imageBytes = dataList.get(position).getImage();
            byte[] imageByteArray = Base64.decode(imageBytes, Base64.DEFAULT);

            Glide.with(context)
                    .load(imageByteArray)
                    .asBitmap()
                    .into(holder.ivResIcon);

            /*Glide.with(context)
                    .load(dataList.get(position).getImage())
                    .thumbnail(0.5f)
                    .crossFade()

                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                    .into(holder.ivResIcon);*/
           // holder.img.setColorFilter(null);
            //holder.iconText.setVisibility(View.GONE);
        } else {
            holder.ivResIcon.setImageResource(R.drawable.ic_perm_identity_gray_24dp);
            //holder.imgProfile.setColorFilter(dataList.getColor());
           // holder.iconText.setVisibility(View.VISIBLE);
        }
    }
Ankesh Roy
  • 278
  • 2
  • 8
  • 33
  • thanks a lot . It slove my issue. But where i am wrong can you figure out. – DevMobApp Feb 08 '18 at 09:20
  • I guess it is because of the `flags` you used while decoding the Base64 string. In the OP you have used `NO_WRAP` while in this answer it is `DEFAULT` and that's why the difference, although I'm not sure about it. Can you update your question with the Base64 string you are getting? – riyaz-ali Feb 08 '18 at 10:19
0

As mentioned in the comment's link If you have converted your image to string by using Base64. You should convert it back with Base64.

Im using this snippet maybe it helps u too.

byte[] data = Base64.decode(iconString, Base64.DEFAULT);
Bitmap imageBitmap = BitmapFactory.decodeByteArray(data, 0, data.length, null); // null for options
imageView.setImageBitmap(imageBitmap);
yilmazburk
  • 907
  • 9
  • 17