Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comparing Bitmap images in Android

Tags:

Is there any way to check if bitmaps are the same? can someone help me out?

like image 231
CMA Avatar asked May 25 '11 06:05

CMA


2 Answers

Bitmap class has method "sameAs" you can use that method to compare two bitmap

http://developer.android.com/reference/android/graphics/Bitmap.html#sameAs%28android.graphics.Bitmap%29

like image 76
Ketan Parmar Avatar answered Sep 28 '22 21:09

Ketan Parmar


It should be something like this:

public boolean equals(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());
}
like image 37
altumano Avatar answered Sep 28 '22 21:09

altumano