I was wondering if there was a way to replace a image in Fresco without reloading it from the server. I have a app where I let the users modify a image and then I upload that new image to the server. However with the way Fresco works I'd need to upload the new image, remove the current one from the cache, then use the new url to retrieve it from the server where it will then be stored in the cache. I can't seem to find a way to just insert the image into the cache using just the url and bitmap as the key and value (if its even possible).
Replace image without server request using Fresco
724 views Asked by Papajohn000 At
2
There are 2 answers
1
On
Fresco currently doesn't support this out of the box, but you could try something like this:
// remove the image from the caches (both disk and memory)
CacheKey diskCacheKey = new SimpleCacheKey(uri.toString());
Fresco.getImagePipelineFactory().getMainDiskStorageCache().remove(diskCacheKey);
Fresco.getImagePipeline().evictFromMemoryCache(uri);
// fill the disk cache (note, memory cache will be filled automatically)
Supplier<FileInputStream> inputStreamSupplier = new Supplier<FileInputStream>() {
@Override
public FileInputStream get() {
return new FileInputStream(path);
}
};
EncodedImage encodedImage = new EncodedImage(inputStreamSupplier);
Fresco.getImagePipelineFactory().getMainBufferedDiskCache().put(diskCacheKey, encodedImage);
// re-set the image to the view
mSimpleDraweeView.setImageUri(uri);
first:
mSimpleDraweeView.setImageUri(null)
to remove cacheand second:
mSimpleDraweeView.getHierarchy().setPlaceholderImage(drawable);
to place a drawable to show the local image;