Caused by: java.lang.IllegalStat

2018-01-16  本文已影响0人  Android小白菜

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);

上一篇下一篇

猜你喜欢

热点阅读