Skip to content

Instantly share code, notes, and snippets.

@graco911
Created March 3, 2018 18:33
Show Gist options
  • Save graco911/7eed9db909e42fa109716ccbddf00320 to your computer and use it in GitHub Desktop.
Save graco911/7eed9db909e42fa109716ccbddf00320 to your computer and use it in GitHub Desktop.
VectorDrawableToBitMapDescriptor
public static BitmapDescriptor getBitmapDescriptor(int id, Context context)
{
if (Build.VERSION.SdkInt >= Build.VERSION_CODES.Lollipop)
{
VectorDrawable vectorDrawable = (VectorDrawable)ContextCompat.GetDrawable(context, id);
int h = vectorDrawable.IntrinsicHeight;
int w = vectorDrawable.IntrinsicWidth;
vectorDrawable.Bounds = new Rect(0, 0, w, h);
Bitmap bm = Bitmap.CreateBitmap(w, h, Bitmap.Config.Argb8888);
Canvas canvas = new Canvas(bm);
vectorDrawable.Draw(canvas);
return BitmapDescriptorFactory.FromBitmap(bm);
}
else
{
return BitmapDescriptorFactory.FromResource(id);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment