Android中图片比较大致的流程如下:
实现的代码如下:
Bitmap actualBitmap = ((BitmapDrawable)actualDrawable).getBitmap(); Bitmap expectedBitmap = ((BitmapDrawable)expectedDrawable).getBitmap(); public static boolean isEqual(Activity activity, Bitmap expectedBitmap, Bitmap actualBitmap) { int nonMatchingPixels = 0; int allowedMaxNonMatchPixels = 10; if(expectedBitmap == null || actualBitmap == null || activity == null) {return false;} int[] expectedBmpPixels = new int[expectedBitmap.getWidth() * expectedBitmap.getHeight()]; expectedBitmap.getPixels(expectedBmpPixels, 0, expectedBitmap.getWidth(), 0, 0, expectedBitmap.getWidth(), expectedBitmap.getHeight()); int[] actualBmpPixels = new int[actualBitmap.getWidth() * actualBitmap.getHeight()]; actualBitmap.getPixels(actualBmpPixels, 0, actualBitmap.getWidth(), 0, 0, actualBitmap.getWidth(), actualBitmap.getHeight()); if (expectedBmpPixels.length != actualBmpPixels.length) {return false;} for (int i = 0; i < expectedBmpPixels.length; i++) { if (expectedBmpPixels[i] != actualBmpPixels[i]) {nonMatchingPixels++;} } if (nonMatchingPixels > allowedMaxNonMatchPixels) {return false;} return true; }
原文:http://www.cnblogs.com/zhujiabin/p/5688854.html