加载带有滑行的图像,而服务器返回base64



当我加载带有以下内容的图像时:

String url = "https://example.com/user/123123/profile_pic" Glide.with(context).load(url).into(imageView);

服务器响应在 base64 中,默认情况下 glide 不处理它

我目前的解决方案:

load image with retrofit -> pass image encoded to glide

在这种情况下,我将失去滑行缓存。我想知道是否有办法通过滑动和处理 base64 响应发出该请求?

您可以将 Base64 字符串转换为字节,然后将该字节加载到滑行中。

byte[] imageByteArray = Base64.decode(imageBytes, Base64.DEFAULT); 
// here imageBytes is base64String
Glide.with(context)
.load(imageByteArray)
.asBitmap()
.into(imageView);

使用自定义模型加载器进行滑行

https://bumptech.github.io/glide/tut/custom-modelloader.html

这个问题的好手册

在课堂上Base64DataFetcher->

public void loadData(@NonNull Priority priority, @NonNull DataCallback<? super ByteBuffer> callback) {  
String base64Section = getBase64SectionOfModel(); 
// get this from Retrofit or another
.........
}

最新更新