android - Fresco 以编程方式将位图添加到缓存

标签 android bitmap fresco

我正在上传一张图片到我的服务器,上传后我的服务器用新的 URI 响应它(可以是与旧的相同的 URL),我想删除旧的缓存图片并插入新的新的 URI。

我尝试通过以下方式实现:

// Retrofit2 onResponse

String newImageUri = response.body().getUri();
String oldImageUri = Preferences.getUser().getImageUrl();   

// Remove old image from cache
Fresco.getImagePipeline().evictFromCache(Uri.parse(oldImageUri));               
Fresco.getImagePipeline().evictFromDiskCache(Uri.parse(oldImageUri));
Fresco.getImagePipeline().evictFromMemoryCache(Uri.parse(oldImageUri));
Fresco.getImagePipelineFactory().getMainFileCache().remove(new SimpleCacheKey(oldImageUri));

// Insert new image at new URI
try {
    Fresco.getImagePipelineFactory().getMainFileCache().insert(new SimpleCacheKey(newImageUri), new WriterCallback() {
        @Override
        public void write(OutputStream os) throws IOException {
            os.write(imageData); // byte[] or the new Bitmap
        }
    });
}
catch (Exception e) {
    e.printStackTrace();
}
uriProfileImage.setImageURI(newImageUri);

没有异常(exception),但我仍然只看到旧图像。

最佳答案

我解决了,是新Uri的Uri格式错误...

关于android - Fresco 以编程方式将位图添加到缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44367039/

相关文章:

android - 提交后折叠搜索 View

android - 在 Android 中搜索 SQLite 数据库

android - 如何在android IconGenerator上将文本居中

.net - Bitmap.SetPixel(x,y, Color) 太慢

android - 如何使用 Fresco 和 Android 以编程方式创建 SimpleDraweeView

android - 如何在Android中完成OCR身份证?

objective-c - kCGImageAlphaPremultipliedFirst 和 kCGImageAlphaFirst

android - 能否禁用/调整 Fresco 对大图像(>2048 像素)的自动调整大小?

android - Picasso v/s Imageloader v/s Fresco vs Glide vs Coil

android - 既然 AdMob 已成为 Google Play 服务的一部分,如何通过 AdRequest 提供位置信息?