Android glide 图片从缓存拿

private class getImageCacheAsyncTask extends AsyncTask<String, Void, File> {
        private final Context context;

        public getImageCacheAsyncTask(Context context) {
            this.context = context;
        }

        @Override
        protected File doInBackground(String... params) {
            String imgUrl =  params[0];
            try {
                return Glide.with(context)
                        .load(imgUrl)
                        .apply(RequestOptions.bitmapTransform(new BlurTransformation(25, 3)))
                        .downloadOnly(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
                        .get();
            } catch (Exception ex) {
                return null;
            }
        }

        @Override
        protected void onPostExecute(File result) {
            if (result == null) {
                return;
            }
            //此path就是对应文件的缓存路径
            String path = result.getPath();

            Bitmap bmp = BitmapFactory.decodeFile(path);
            list.add(bmp);
        }
    }

猜你喜欢

转载自blog.csdn.net/FlyPig_Vip/article/details/83624424