我在手动将本地镜像添加到磁盘缓存时遇到问题。原因是我有一张本地照片,需要上传这张。但是因为我知道 URL 结果,所以我想立即缓存它。我正在使用
ImageLoader.getInstance().getDiscCache().put(imageUrl, new File(tempFileURI));
但这不起作用,因为当我使用下面的行时,文件返回 null
File thumb=
DiscCacheUtil.findInCache(urlThumbSize,ImageLoader.getInstance().getDiscCache());
有什么想法吗?
最佳答案
实际上,DiscCache 并不打算直接使用。 DiscCache.put()
不会将您的文件复制到磁盘缓存中。如果它是有限的缓存,它只是控制缓存大小。
您应该自己将图像文件复制到缓存目录中:
File fileInDiscCache = discCache.get(imageUri);
// copy your file into 'fileInDiscCache' file
discCache.put(imageUri, fileInDiscCache);
关于android - 如何强制将图像添加到磁盘缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20684949/