Created
February 16, 2019 06:40
-
-
Save umpteenthdev/d99dbd0abf27f75b2d44137972abe18d to your computer and use it in GitHub Desktop.
How to get bitmap from vector
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
| fun Context.vectorToBitmap(@DrawableRes id: Int): Bitmap { | |
| val drawable = ContextCompat.getDrawable(this, id)!! | |
| val bitmap = Bitmap.createBitmap(drawable.intrinsicWidth, drawable.intrinsicHeight, Bitmap.Config.ARGB_8888) | |
| val canvas = Canvas(bitmap) | |
| drawable.setBounds(0, 0, canvas.width, canvas.height) | |
| drawable.draw(canvas) | |
| return bitmap | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment