我试图从facebook的profilepictureview创建一个圆形位图,但我得到一个我无法弄清楚的nullpointer:
ImageView fbimage = ( ( ImageView)userProfilePictureView.getChildAt( 0));
Bitmap bitmap = ( ( BitmapDrawable) fbimage.getDrawable()).getBitmap();
Bitmap circleBitmap = Bitmap.createBitmap(bitmap.getWidth(),bitmap.getHeight(),Bitmap.Config.ARGB_8888);
BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
Paint paint = new Paint();
paint.setShader(shader);
paint.setAntiAlias(true);
Canvas c = new Canvas(circleBitmap);
c.drawCircle(bitmap.getWidth()/2,bitmap.getHeight()/2,bitmap.getWidth()/2,paint);
fbimage.setImageBitmap(circleBitmap);
我在这条线上得到了NPE:
Bitmap bitmap = ( ( BitmapDrawable) fbimage.getDrawable()).getBitmap();
这是我的班级(以及完整的堆栈):https://gist.github.com/RidouaneHicham/edce609a4f5aaa59af9a
谢谢!