안드로이드 Bitmap 비교 방법
안드로이드 Bitmap 비교 하기
Bitmap 클래스에 sameAs(Bitmap other) 메소드로 비교할 수 있다.
이 메소드는 API Level 12버전부터 추가되어 이하 API버전에서는 사용할 수 가 없다는거...
( http://developer.android.com/reference/android/graphics/Bitmap.html#sameAs%28android.graphics.Bitmap%29 )
구글링해서 답을 찾았다.
(주소: http://stackoverflow.com/questions/6120439/comparing-bitmap-images-in-android )
/**
* Bitmap을 비교.
* @param bitmap1
* @param bitmap2
* @return boolean
*/
private boolean sameAs(Bitmap bitmap1, Bitmap bitmap2) {
ByteBuffer buffer1 = ByteBuffer.allocate(bitmap1.getHeight() * bitmap1.getRowBytes());
bitmap1.copyPixelsToBuffer(buffer1);
ByteBuffer buffer2 = ByteBuffer.allocate(bitmap2.getHeight() * bitmap2.getRowBytes());
bitmap2.copyPixelsToBuffer(buffer2);
return Arrays.equals(buffer1.array(), buffer2.array());
}