02-14 10:01:11.340: E/AndroidRuntime(30492): at android.graphics.Bitmap.setPixels(Bitmap.java:1447)
02-14 10:01:11.340: E/AndroidRuntime(30492): at com.example.music.utils.FastBlur.doBlur(FastBlur.java:237)
02-14 10:01:11.340: E/AndroidRuntime(30492): at com.example.music.activity.PlayActivity.showArtwork(PlayActivity.java:167)
02-14 10:01:11.340: E/AndroidRuntime(30492): at com.example.music.activity.PlayActivity.initView(PlayActivity.java:153)
02-14 10:01:11.340: E/AndroidRuntime(30492): at com.example.music.activity.PlayActivity.onResume(PlayActivity.java:132)
02-14 10:01:11.340: E/AndroidRuntime(30492): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1197)
02-14 10:01:11.340: E/AndroidRuntime(30492): at com.lbe.security.service.core.client.b.x.callActivityOnResume(Unknown Source)
02-14 10:01:11.340: E/AndroidRuntime(30492): at android.app.Activity.performResume(Activity.java:5430)
02-14 10:01:11.340: E/AndroidRuntime(30492): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2971)
02-14 10:01:11.340: E/AndroidRuntime(30492): ... 12 more
今天遇到IllegalStateException,在 bitmap.setPixels方法中会挂
原因如下
BitmapFactory.decodeStream(context.getResources().openRawResource(R.drawable.defaultalbum), null, opts); 返回的bitmap is not mutable
各种Bitmap方法返回的Bitmap有的可以mutable有的不可以
1。static Bitmap createBitmap(Bitmap src)
Returns an immutable bitmap from the source bitmap.
2.static Bitmap createBitmap(int[] colors, int width, int height, Bitmap.Config config)
Returns a immutable bitmap with the specified width and height,
3.static Bitmap createBitmap(int[] colors, int offset, int stride, int width, int height, Bitmap.Config config)
Returns a immutable bitmap with the specified width and height,
4.static Bitmap createBitmap(Bitmap source, int x, int y, int width, int height, Matrix m, boolean filter)
Returns an immutable bitmap from subset of the source bitmap,
5.static Bitmap createBitmap(int width, int height, Bitmap.Config config)
Returns a mutable bitmap with the specified width and height.
6.static Bitmap createBitmap(Bitmap source, int x, int y, int width, int height)
Returns an immutable bitmap from the specified subset of the source bitmap.
解决方法:可把Bitmap复制一下转换成可mutable在进行setPixels操作
Bitmap bgBitmap =bm.copy(Bitmap.Config.ARGB_8888, true);