Is there a way to compare two Bitmaps
that are wrapped BitmapDrawable
.
The comparison should not end if the sizes do not match, but they must match the pixels and color Bitmap
I'm not sure how the native part of Android draws Bitmap
, because it sameAs
returns true, even if the color of the hue is different.
If the size is different, I can create a scaled one Bitmap
from another and compare it with.
In my source code I use DrawableCompat.setTint
c ImageViews
Drawable
, and in the test code I load Drawable
from resources and align it in the same way.
Any ideas? I would like to have a test that checks the original Drawable
of ImageView
and the color also based on clicking on it or not.
NOTE 1: My drawings are white and I use a hue to set the color. Cyclic pixels for Bitmaps
do not work, because at this moment they are white, most likely, on the Android side, the hue color is used when drawing.
NOTE 2: The use compile 'com.android.support:palette-v7:21.0.0'
and Palette.from(bitmap).generate();
does not help either because the palette has returned 0 samples, so it can not get out there no color information.
This is my current match:
public static Matcher<View> withDrawable(final Drawable d) {
return new BoundedMatcher<View, ImageView>(ImageView.class) {
@Override
public boolean matchesSafely(ImageView iv) {
if (d == null) {
return iv.getDrawable() == null;
} else if (iv.getDrawable() == null) {
return false;
}
if (d instanceof BitmapDrawable && iv.getDrawable() instanceof BitmapDrawable) {
BitmapDrawable d1 = (BitmapDrawable) d;
BitmapDrawable d2 = (BitmapDrawable) iv.getDrawable();
Bitmap b1 = d1.getBitmap();
Bitmap b2 = d2.getBitmap();
return b1.sameAs(b2);
}
return iv.getDrawable().getConstantState().equals(d.getConstantState());
}
@Override
public void describeTo(Description description) {
description.appendText("with drawable: ");
}
};
}
Thanks.
source
share