Skip to content

Instantly share code, notes, and snippets.

@umpteenthdev
Created February 16, 2019 06:40
Show Gist options
  • Select an option

  • Save umpteenthdev/d99dbd0abf27f75b2d44137972abe18d to your computer and use it in GitHub Desktop.

Select an option

Save umpteenthdev/d99dbd0abf27f75b2d44137972abe18d to your computer and use it in GitHub Desktop.
How to get bitmap from vector
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