Created
March 3, 2018 18:33
-
-
Save graco911/7eed9db909e42fa109716ccbddf00320 to your computer and use it in GitHub Desktop.
VectorDrawableToBitMapDescriptor
This file contains 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
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