Skip to content

Instantly share code, notes, and snippets.

@EfeBudak
Last active August 10, 2018 04:46
Show Gist options
  • Save EfeBudak/a9ec13d9d582c6cc7f11156e6775ea47 to your computer and use it in GitHub Desktop.
Save EfeBudak/a9ec13d9d582c6cc7f11156e6775ea47 to your computer and use it in GitHub Desktop.
Vector drawable to bitmap
public static BitmapDescriptor generateBitmapDescriptorFromRes(
Context context, int resId) {
Drawable drawable = ContextCompat.getDrawable(context, resId);
drawable.setBounds(
0,
0,
drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight());
Bitmap bitmap = Bitmap.createBitmap(
drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight(),
Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.draw(canvas);
return BitmapDescriptorFactory.fromBitmap(bitmap);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment