Android Bitmap 会抛出 java.lang.IllegalStateException: only mutable bitmaps may be reconfigured
2017-08-04 22:03
921 查看
Android
Bitmap 改变的时候可能会抛出 java.lang.IllegalStateException: only mutable bitmaps may be reconfigured
然后就报出 java.lang.IllegalStateException 这个错误,
only
mutable bitmaps may be reconfigured
mutable : 易变的,不定的
mutable 作用 : 控制bitmap的setPixel方法能否使用,也就是外界能否修改bitmap的像素。
会先判断bitmap.isMutable()是否为true,如果为false,也就是是不是易变的图片,如果是true,则可以更改,否者
就会抛出 java.lang.IllegalStateException异常。为什么呢?
isMutable( )是易变的、可以修改的意思,而
Bitmap.createBitmap(mWidth, mHeight, Config.ARGB_8888) 为 mutable 为true
BimapFactory.decodeResource() 得到的mutable 为false, 要想其为true
一般会
BimtapFactory.decodeResource().copy(configu_argb_8888, true);
mBitmap =
bitmap.copy(Bitmap.Config.ARGB_8888, true)
这句话,这个时候就相当于复制了一个新的可变的Bitmap,这个时候就不会报错了,问题解决!
Bitmap 改变的时候可能会抛出 java.lang.IllegalStateException: only mutable bitmaps may be reconfigured
bitmap.setHeight(12);
bitmap.setWidth(12);
然后就报出 java.lang.IllegalStateException 这个错误,
only
mutable bitmaps may be reconfigured
mutable : 易变的,不定的
mutable 作用 : 控制bitmap的setPixel方法能否使用,也就是外界能否修改bitmap的像素。
会先判断bitmap.isMutable()是否为true,如果为false,也就是是不是易变的图片,如果是true,则可以更改,否者
就会抛出 java.lang.IllegalStateException异常。为什么呢?
isMutable( )是易变的、可以修改的意思,而
bitmap.setHeight(12);
Bitmap.createBitmap(mWidth, mHeight, Config.ARGB_8888) 为 mutable 为true
BimapFactory.decodeResource() 得到的mutable 为false, 要想其为true
一般会
BimtapFactory.decodeResource().copy(configu_argb_8888, true);
mBitmap =
bitmap.copy(Bitmap.Config.ARGB_8888, true)
这句话,这个时候就相当于复制了一个新的可变的Bitmap,这个时候就不会报错了,问题解决!
相关文章推荐
- java.lang.IllegalStateException: ActionBarContextView can only be used with android:layout_width="
- java.lang.RuntimeException: Only one Looper may be created per thread
- android 如何分析java.lang.IllegalArgumentException: Cannot draw recycled bitmaps异常
- java.lang.ClassCastException: android.app.Application cannot be cast to serialport_api.sample.App问题
- android利用Bitmap加载图片所遇到的一个奇怪的OOM问题java.lang.OutOfMemoryError
- android Multiple markers at this line - The type java.lang.Class cannot be resolved. It is indirectl
- java.lang.ClassCastException: android.app.Application cannot be cast to greendroid.app.MyApplication
- Android 图片大小超过预算的VM:java.lang.OutOfMemoryError: bitmap size exceeds VM budget
- 关于android编程遇到java.lang.OutOfMemoryError: bitmap size exceeds VM budget此类问题的原因及解决办法
- android Multiple markers at this line - The type java.lang.Class cannot be resolved. It is indirectl
- Android解决java.lang.OutOfMemoryError: bitmap size exceeds VM budget
- Bitmap.createBitmap java.lang.IllegalArgumentException: width and height must be > 0 问题解决
- java.lang.UnsatisfiedLinkError: 动态库 : 动态库:only ET_DYN and ET_EXEC can be loaded
- android:java.lang.OutOfMemoryError: bitmap size exceeds VM budget---缩略图
- java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.w
- android-java.lang.OutOfMemoryError: bitmap size exceeds VM budge
- Android解决java.lang.OutOfMemoryError: bitmap size exceeds VM budget
- android-java.lang.OutOfMemoryError: bitmap size exceeds VM budge
- android java.lang.OutOfMemoryError: bitmap size exceeds VM budget
- java.lang.RuntimeException: Errors accessing files. There may be spaces in your image's filename.