diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/BitmapUtils.java')
-rw-r--r-- | platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/BitmapUtils.java | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/BitmapUtils.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/BitmapUtils.java index 5584a6eb58..f14e49cb6a 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/BitmapUtils.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/BitmapUtils.java @@ -8,9 +8,12 @@ import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.annotation.VisibleForTesting; import android.view.View; import java.io.ByteArrayOutputStream; +import java.nio.ByteBuffer; +import java.util.Arrays; /** * Utility class for creating bitmaps @@ -121,4 +124,23 @@ public class BitmapUtils { return new BitmapDrawable(context.getResources(), compass); } + + /** + * Validates if the bytes of a bitmap matches another + * + * @param bitmap the bitmap to be compared against + * @param other the bitmap to compare with + * @return true if equal + */ + @VisibleForTesting + public static boolean equals(Bitmap bitmap, Bitmap other) { + ByteBuffer buffer = ByteBuffer.allocate(bitmap.getHeight() * bitmap.getRowBytes()); + bitmap.copyPixelsToBuffer(buffer); + + ByteBuffer bufferOther = ByteBuffer.allocate(other.getHeight() * other.getRowBytes()); + other.copyPixelsToBuffer(bufferOther); + + return Arrays.equals(buffer.array(), bufferOther.array()); + } + } |