0
這是我使用轉換雙色圖片爲灰度和像素比較它們像素的代碼。儘管我的應用程序保持關閉。這裏的代碼:轉換ColorBitmap到GrayscaleBitmap不斷崩潰
public boolean equals(Bitmap bitmap1, Bitmap bitmap2) {
Bitmap grayscaleBitmap1 = Bitmap.createBitmap(
bitmap1.getWidth(), bitmap1.getHeight(),
Bitmap.Config.RGB_565);
Canvas c = new Canvas(grayscaleBitmap1);
Paint p = new Paint();
ColorMatrix cm = new ColorMatrix();
cm.setSaturation(0);
ColorMatrixColorFilter filter = new ColorMatrixColorFilter(cm);
p.setColorFilter(filter);
c.drawBitmap(bitmap1, 0, 0, p);
Bitmap grayscaleBitmap2 = Bitmap.createBitmap(
bitmap2.getWidth(), bitmap2.getHeight(),
Bitmap.Config.RGB_565);
Canvas c1 = new Canvas(grayscaleBitmap2);
c1.drawBitmap(bitmap2, 0, 0, p);
ByteBuffer buffer1 = ByteBuffer.allocate(grayscaleBitmap1.getHeight()
* grayscaleBitmap1.getRowBytes());
grayscaleBitmap1.copyPixelsToBuffer(buffer1);
ByteBuffer buffer2 = ByteBuffer.allocate(grayscaleBitmap2.getHeight()
* grayscaleBitmap2.getRowBytes());
grayscaleBitmap2.copyPixelsToBuffer(buffer2);
return Arrays.equals(buffer1.array(), buffer2.array());
}
這是logcat。
那笨拙的我。謝謝。 –
我已經寫了,你應該怎麼寫this.please檢查 –
,我知道該怎麼做,只是貼一些代碼到的AsyncTask並沒有意識到它有一個烤麪包。 –