Skip to content

Instantly share code, notes, and snippets.

@sromku
Created January 29, 2017 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sromku/8fd7e94a79eca127c0ed3f342f6500d7 to your computer and use it in GitHub Desktop.
Save sromku/8fd7e94a79eca127c0ed3f342f6500d7 to your computer and use it in GitHub Desktop.
Getting Bitmap from obfuscated RoundedBitmapDrawable from support v4 lib. Good for matching Bitmaps in espresso.
public static Bitmap getBitmapFromRoundedBitmapDrawable(RoundedBitmapDrawable drawable) {
Bitmap origin = null;
try {
Field[] declaredFields = RoundedBitmapDrawable.class.getDeclaredFields();
for (Field field : declaredFields) {
if (field.getType().isAssignableFrom(Bitmap.class)) {
field.setAccessible(true);
origin = (Bitmap) field.get(drawable);
break;
}
}
return origin;
} catch (Exception e) {
// ...
}
return origin;
}
@sromku
Copy link
Author

sromku commented Jan 29, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment