使用 setPixels 的错误

我想编辑 images,但是使用 setPixels 时获得错误

 picw = pic.getWidth();
        pich = pic.getHeight();
        picsize = picw*pich;        
        int[] pix = new int [picsize];
        pic.getPixels(pix, 0, picw, 0, 0, picw, pich);  
        pic.setPixels(pix,0,pic.getWidth(),0,0,pic.getWidth(),pic.getHeight());

使用 setPixels 获得非法状态异常

由于: java.lang.IllegalStateException
   android.graphics.Bitmap.setPixels(Bitmap.java:878)
   com.sandyapps.testapp.testapp.onCreate(testapp.java:66)

根据文档中的说明

public void setPixel (int x, int y, int color)

Since: API Level 1
Write the specified Color into the bitmap (assuming it is mutable) at the x,y coordinate.
Parameters

x   The x coordinate of the pixel to replace (0...width-1)
y   The y coordinate of the pixel to replace (0...height-1)
color   The Color to write into the bitmap
Throws

IllegalStateException   if the bitmap is not mutable
IllegalArgumentException    if x, y are outside of the bitmap's bounds.

IllegalStateException表示这个位图是不可变的,要修改就自己建一个副本吧

我觉得 Bitmap 没变。
如果这样的话创建一个可变的 Bitmap 复本,使用Bitmap.copy(Bitmap.Config config, boolean isMutable)