Caused by: java.lang.IllegalStateException: Immutable bitmap passed to Canvas constructor

Caused by: java.lang.IllegalStateException: Immutable bitmap passed to Canvas constructor

Bitmap bmp =BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); Paint paint =new Paint();

paint.setColor(Color.BLACK);

String str ="123";

Canvas canvas =new Canvas(bmp);    //此句报错

canvas.drawText(str, 0,0, paint);

不允许直接修改res里面的图片,只要在后面加上.copy(Bitmap.Config.ARGB_8888, true);

修改后:

Bitmap  originalBitmap = BitmapFactory.decodeResource(getResources(),R.drawable.a).copy(Bitmap.Config.ARGB_8888, true);

你可能感兴趣的:(Caused by: java.lang.IllegalStateException: Immutable bitmap passed to Canvas constructor)