bitmap.setPixel抛出了IllegalStateException 异常

Posted 学无止境

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了bitmap.setPixel抛出了IllegalStateException 异常相关的知识,希望对你有一定的参考价值。

使用BitmapFactory.decodeResource创建出的Bitmap对象是immutable的,因此在调用其.setPixel方法时会抛出IllegalStateException异常。

解决方法:创建副本

若要使topImage这个Bitmap变成mutable,可以使用下面的代码: 

topImage = topImage.copy(Bitmap.Config.ARGB_8888, true);

以上是关于bitmap.setPixel抛出了IllegalStateException 异常的主要内容,如果未能解决你的问题,请参考以下文章