How to load image through byte array using Glide?

前端 未结 5 1435
抹茶落季
抹茶落季 2020-12-08 13:46

I have an image contents byte[] form. But when i load them through Glide then broken images are shown. what I\'m doing is shown below.

Glide.with(context)
           


        
5条回答
  •  醉话见心
    2020-12-08 14:20

    Lets say your base64 string is

    String imageBytes = "HVao14fpmtHSev3OgsrQNsawkFzXNcY3BsfQla6..."
    

    You should convert imageBytes String to array of bytes through

    byte[] imageByteArray = Base64.decode(imageBytes, Base64.DEFAULT);
    

    afterwards pass this imageByteArray to Glide.

    Glide.with(context)
        .load(imageByteArray)
        .asBitmap()
        .placeholder(R.drawable.ic_broken)
        .into(rowImageView);
    

提交回复
热议问题