Retrofit API to retrieve a png image

后端 未结 8 1275
我在风中等你
我在风中等你 2020-12-02 20:32

Hi I am new to Retrofit framework for Android. I could get JSON responses from REST services using it but I don\'t know how to download a png using retrofit. I am trying to

8条回答
  •  Happy的楠姐
    2020-12-02 20:58

    Retrofit is encoding your byte array to base 64. So decode your string and you are good to go. In this way you can retrieve a list of images.

    public static Bitmap getBitmapByEncodedString(String base64String) {
        String imageDataBytes = base64String.substring(base64String.indexOf(",")+1);
        InputStream stream = new ByteArrayInputStream(Base64.decode(imageDataBytes.getBytes(), Base64.DEFAULT));
        return BitmapFactory.decodeStream(stream);
    }
    

提交回复
热议问题