Created
January 29, 2017 13:13
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As extension to this gist: https://gist.github.com/frankiesardo/7490059