我正在嘗試開發可應用現有圖像的一些基本效果的應用程序。我和它差不多都是O.K。但是當我玩像素時,它停止了工作。有人可以幫我解決嗎?我應該使用另一個線程而不是主線程來編寫下面的代碼嗎?將圖像轉換爲灰度圖像時,應用程序未響應
int[] imagePixels = new int[picWidth * picHeight];
bitmap.getPixels(imagePixels, 0, picWidth, 0, 0, picWidth, picHeight);
for (int y = 0; y < picHeight; y++) {
for (int x = 0; x < picWidth; x++) {
int index = y * picWidth + x;
int red = (imagePixels[index] >> 16) & 0xff;
int green = (imagePixels[index] >> 8) & 0xff;
int blue = imagePixels[index] & 0xff;
red = (int) Math.abs(red-255);
green = (int) Math.abs(green-255);
blue = (int) Math.abs(blue-255);
imagePixles[index] = 0xff000000 | (red << 16) | (green << 8) | blue;
}
}
bitmap.setPixels(imagePixels, 0, picWidth, 0, 0, picWidth, picHeight);
「停止工作」是什麼意思?請更加明確。 – Egor 2013-03-12 10:52:40
我應該使用另一個線程而不是主線程來編寫下面的代碼嗎? >是的 – 2013-03-12 10:55:01
@Egor Android對我說,我的應用程序沒有響應等待和取消兩個選項。 – user3430287 2013-03-12 11:07:25