Bitmap is null when convert imageview in bitmap
我需要在图像中放置效果模糊,但是将imageview转换为位图时会显示错误(NullPointerException)。
查看代码:
1 2 3 | // mImages is a list of string (links http of images in web) Picasso.with(mContext).load(mImages.get(position)).fit().centerInside().into(imageView); Bitmap bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap(); |
使用Picasso回调:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | Picasso.with(this) .load(mImages.get(position)) .fit() .centerInside() .into(imageView, new Callback() { @Override public void onSuccess() { // Drawable is ready Bitmap bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap(); } @Override public void onError() { } }); |
确保您的ImageView的
这是因为
如果
您确定imageView!= null吗?如果条件
,将其package在里面
1 2 3 4 5 6 | if(imageView != null){ // write your code here }else{ //log something like the following Log.e("imageView","NULL"); } |
您确定它是内置的吗?尝试下一个代码
1 2 | imageView.buildDrawingCache(); Bitmap bmap = imageView.getDrawingCache(); |