Skip to content

Instantly share code, notes, and snippets.

@iRYO400
Created July 24, 2018 04:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iRYO400/81e25804d2e4e142484e3f773a6c2309 to your computer and use it in GitHub Desktop.
Save iRYO400/81e25804d2e4e142484e3f773a6c2309 to your computer and use it in GitHub Desktop.
A-snippet #3 Drawable to BitmapDescriptor
private fun bitmapDescriptorFromVector(vectorResId: Int, context: Context): BitmapDescriptor {
val vectorDrawable = ContextCompat.getDrawable(context, vectorResId)
vectorDrawable!!.setBounds(0, 0, vectorDrawable.intrinsicWidth, vectorDrawable.intrinsicHeight)
val bitmap = Bitmap.createBitmap(vectorDrawable.intrinsicWidth, vectorDrawable.intrinsicHeight, Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap)
vectorDrawable.draw(canvas)
return BitmapDescriptorFactory.fromBitmap(bitmap)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment