位图花费太多时间加载

时间:2016-12-20 06:55:52

标签: android bitmap imageview imageloader

我正在尝试在ImageView中实现加载位图,但加载时间太长。我也使用过ImageLoader但它只支持url,它不支持位图,所以如何立即显示位图?请帮忙解决一下!

使用图像加载器显示图像

对于url我使用了这段代码

imgLoader.DisplayImage(mImage, R.mipmap.ic_launcher, imgProfile);

1 个答案:

答案 0 :(得分:0)

您可以使用任何ImageLoader library,例如GlidePicasso

以下是使用Glide

的代码段
Glide.with(mContext)
                .load(your_image_url_or_resource_id)
                .asBitmap()
                .into(new SimpleTarget<Bitmap>() {
                    @Override
                    public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                        // you can do something with loaded bitmap here

                        yourImageViewRef.setImageBitmap(resource);
                    }
                });

如果您想使用网址加载图片,请尝试使用此代码

Glide.with(context).load(your_image_url_or_resource_id).placeholder(R.drawable.placeholder_icon)
                    .error(R.drawable.error_icon).into(yourImageViewRef);
相关问题