我正在使用Glide在我的应用程序中显示图像.现在我想知道Glide存储从网址下载的缓存图像的位置.

我使用下面的代码来显示图像.

Glide.with(mContext)

.load(mData.get(position).getImage())

.centerCrop()

.override(300, 300)

.placeholder(R.drawable.default_small)

.diskCacheStrategy(DiskCacheStrategy.SOURCE)

.into(holder.ivCapturedImage);

最佳答案

private String getImgCachePath(String url) {

FutureTarget futureTarget = Glide.with(getBaseContext()).load(url).downloadOnly(100, 100);

try {

File file = futureTarget.get();

String path = file.getAbsolutePath();

return path;

} catch (InterruptedException e) {

e.printStackTrace();

} catch (ExecutionException e) {

e.printStackTrace();

}

return null;

}

参数url是图片的网络地址,100,100是缓存图片的宽度和高度,您可以根据需要进行更改.

然后,路径是缓存路径.

更多推荐