DevMobApp
DevMobApp

Reputation: 125

How to set Decoded bytes to Imageview

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);

Upvotes: 1

Views: 284

Answers (2)

Ankesh Roy
Ankesh Roy

Reputation: 278

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);
        }
    }

Upvotes: 1

yilmazburk
yilmazburk

Reputation: 917

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);

Upvotes: 0

Related Questions