且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Glide载入图片后保存图片

更新时间:2023-02-02 21:49:15

使用侦听器,以便在提取图像并准备使用它时,可以使用您的saveImage方法保存它.

Use the listener so that when the image is fetched and ready to be used, you can save it using the saveImage method of yours.

执行此操作:

Glide.with(getContext()).load(apdInfo.url)
     .thumbnail(0.5f)
     .crossFade()
     .diskCacheStrategy(DiskCacheStrategy.ALL)
     .into(new SimpleTarget<GlideDrawable>() {
                @Override
                public void onResourceReady(GlideDrawable glideDrawable, GlideAnimation<? super GlideDrawable> glideAnimation) {
                    apd_image.setImageDrawable(glideDrawable);
                    apd_image.setDrawingCacheEnabled(true);
                    saveImage();
      }});

在onResourceReady()回调中调用saveImage方法,并使用GlideDrawable资源.我建议使用GlideDrawable而不是使用Drawing Cache获取图像.

Call the saveImage method inside onResourceReady() callback and use the GlideDrawable resource. I would suggest using the GlideDrawable rather than getting the image using Drawing Cache.