将图片异步加载为位图并获取异常

时间:2019-10-16 13:28:40

标签: android glide

Android Studio 3.5。

我需要将异步图片加载到位图。如果加载失败,则获取例外。这里是代码段:

 private Bitmap bannerImageBitmap;

        Glide.with(this)
                .asBitmap()
                .load(imageURL)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .skipMemoryCache(false)
                .addListener(new RequestListener<Bitmap>() {
                    @Override
                    public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Bitmap> target, boolean isFirstResource) {
                        // do some with exception
                        return false;
                    }

                    @Override
                    public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) {
                        bannerImageBitmap = resource;
                        onLoadSuccess();
                        return false;
                    }
                }).submit();
    }

这是正确的方法吗?

0 个答案:

没有答案