我想編輯 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表示這個位圖是不可變的,要修改就自己建一個副本吧