Bitmap: java.lang.IllegalStateException

在使用bitmap.setPixels(pix, 0, w, 0, 0, w, h); 的时候出现的错误。
原因:

  Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.icon2);//返回的估计是一个immutalbe的bitmap,所以不能用setpixels
  Bitmap b = Bitmap.createBitmap(2, 2, Bitmap.Config.ARGB_8888);//返回的是一个mutable的bitmap,可以用setpixels

成功的代码:

Bitmap oldBit = BitmapFactory.decodeResource(activity.getResources(), R.drawable.user_cover);
Bitmap newBmp = Bitmap.createBitmap(oldBit.getWidth(), oldBit.getHeight(), Bitmap.Config.ARGB_8888);

Canvas c = new Canvas(newBmp);
c.drawBitmap(oldBit, 0, 0, new Paint());

Bitmap over = FastBlur.doBlur(newBmp, 10, true);      
imageView.setImageBitmap(over);

你可能感兴趣的:(Bitmap: java.lang.IllegalStateException)