Skip to content

Instantly share code, notes, and snippets.

@gordinmitya
Created October 29, 2018 14:58
Show Gist options
  • Save gordinmitya/b4752da18de6df93040c77ccd11302f1 to your computer and use it in GitHub Desktop.
Save gordinmitya/b4752da18de6df93040c77ccd11302f1 to your computer and use it in GitHub Desktop.
private Bitmap loadFromSvg(String name) {
File file = new File(getDirectory(), name + ".svg");
if (!file.exists()) return null;
Drawable drawable = VectorDrawableCompat.createFromPath(file.getAbsolutePath());
if (drawable == null) return null;
Bitmap bitmap = Bitmap.createBitmap(
drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight(),
Bitmap.Config.ARGB_8888
);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment