Skip to content

Instantly share code, notes, and snippets.

@utsmannn
Created June 24, 2020 09:26
Show Gist options
  • Save utsmannn/f4292a95400492bbea0b79f3a8244ee8 to your computer and use it in GitHub Desktop.
Save utsmannn/f4292a95400492bbea0b79f3a8244ee8 to your computer and use it in GitHub Desktop.
fun bitmapFromVector(context: Context, @DrawableRes icon: Int): BitmapDescriptor {
val background = ContextCompat.getDrawable(context, icon)
background!!.setBounds(0, 0, background.intrinsicWidth, background.intrinsicHeight)
val bitmap = Bitmap.createBitmap(background.intrinsicWidth, background.intrinsicHeight, Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap)
background.draw(canvas)
return BitmapDescriptorFactory.fromBitmap(bitmap)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment