Android code to fetch Image from server and display it in Imageview

后端 未结 4 1513
逝去的感伤
逝去的感伤 2020-12-22 08:11

Hi I know how to fetch an string from jsonobject, but my question is how to fetch an image from Rest api and display it. The image is stored as profile_image in jsonobject

4条回答
  •  梦毁少年i
    2020-12-22 08:26

    If your image data in "profile_image" is Base64 encoded string then you can convert to bitmap by following.

    if(object.has("profile_image")) 
    {
         byte[] decodedString = Base64.decode(object.getString("profile_image", Base64.DEFAULT);
         Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length); 
    }
    

提交回复
热议问题