之后,毕加索加载安卓得到绘制的图像 [英] android get Drawable image after picasso loaded

查看:168
本文介绍了之后,毕加索加载安卓得到绘制的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的毕加索库从URL加载图像。在code我用的是下面。

I am using Picasso library to load image from url. The code I used is below.

Picasso.with(getContext()).load(url).placeholder(R.drawable.placeholder)
                .error(R.drawable.placeholder).into(imageView);

我想要做的是让从URL加载的图像。我用

What I wanna do is to get the image that loaded from url. I used

Drawable image = imageView.getDrawable();

不过,这并总是从URL返回图像加载图像占位符代替。难道你们有什么想法?我应该如何访问绘制的图像,它只是从URL加载。

However, this will always return placeholder image instead of the image load from url. Do you guys have any idea? How should I access the drawable image that it's just loaded from url.

在此先感谢。

推荐答案

这是因为图像加载异步。你需要得到提拉,当它完成加载到视图:

This is because the image is loading asynchronously. You need to get the drawable when it is finished loading into the view:

   Target target = new Target() {
          @Override
          public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
              imageView.setImageBitmap(bitmap);
              Drawable image = imageView.getDrawable();
          }

          @Override
          public void onBitmapFailed() {
          }
   }

   Picasso.with(this).load("url").into(target);

这篇关于之后,毕加索加载安卓得到绘制的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆