如何从NetworkImageView获取位图

时间:2014-12-09 05:57:50

标签: android android-volley networkimageview

我想要来自networkimageview的Bitmap。这是我的代码和

    String url="https://graph.facebook.com/"+u_id+"/picture";
    mNetworkImageView = (NetworkImageView) findViewById(R.id.networkImageView);
    mImageLoader = MySingletonClass.getInstance(this).getImageLoader();
    mNetworkImageView.setImageUrl(url, mImageLoader);

在此之后,我想要来自networkimageview的位图。怎么弄明白?

2 个答案:

答案 0 :(得分:6)

        mImageLoader.get(url, new ImageLoader.ImageListener() {

        public void onErrorResponse(VolleyError arg0) {
           // image.setImageResource(R.drawable.icon_error); // set an error image if the download fails
        }

        public void onResponse(ImageContainer response, boolean arg1) {
            if (response.getBitmap() != null) {
                mNetworkImageView.setImageBitmap(CircleImage.getRoundedRectBitmap(response.getBitmap(), 100));
            } //else
               // image.setImageResource(R.drawable.icon_loading); // set the loading image while the download is in progress
        }
    });

答案 1 :(得分:3)

试试这个:

Bitmap bitmap = ((BitmapDrawable) mNetworkImageView.getDrawable()).getBitmap();

修改

我检查了Volley代码,发现他们正在使用标签来存储有关图片的信息,所以,试试这个:

ImageContainer container = (ImageContainer) mNetworkImageView.getTag();
final Bitmap bitmap = container.getBitmap();
if (bitmap != null) {
    //other code to processing bitmap
}