Created
January 24, 2020 12:16
-
-
Save juniorcesarabreu/d79fcb5c705ab34c9911f8b80b41c2fc to your computer and use it in GitHub Desktop.
Bitmap from VectorDrawable
This file contains 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 getBitmapFromVectorDrawable(Context context, int drawableId) { | |
Drawable drawable = ContextCompat.getDrawable(context, drawableId); | |
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { | |
drawable = (DrawableCompat.wrap(drawable)).mutate(); | |
} | |
Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), | |
drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); | |
Canvas canvas = new Canvas(bitmap); | |
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); | |
drawable.draw(canvas); | |
return bitmap; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment