To summarize, now we have:
- Pretty small.
- Pure Java.
- Reliable and fast.
- CSS support.
- Gradients (including radial), transformations and paints.
- Fonts, texts and text spans.
- Drawing primitives, paths and polygons.
- Strokes and fills, including alpha, dashes, joins and other.
- XLink support included.
- Raster images in SVG support (external, from assets or embedded).
- SVG filters initial support.
- SVG and SVGZ support.
Moreover, we have tested huge SVG files with dozens of megabytes each. Depending on the SVG files and transport (local or from Internet) it might be “pretty fast” or “acceptable”, but it really works in all cases.
The following features are not supported:
- Declarative animation for SVG.
- Interactive and dynamic SVG documents.
- Raster images in strange formats.
- HTML tags around.
It is just a small, fast and easy-to-use library which was designed to support “pure vector” icons, backgrounds and etc. No overloading on this stage. In case anybody requests it – our team will expand the library according their needs. It’s not a big problem for our team.
The core of the library is “libsvg.aar”. It does everything from fast SAX-based parsing, rendering .svg files for Android at the bitmaps and surfaces, computers corresponding CSS styles defined in .svg and more.
It provides an API (primarily SVGHelper class) to operate with files in a typical stream-like manner.
Libsvg.aar supports many graphical features defined in SVG 1.1 and SVG 1.2. But it is intended to render only static images without animation, filters and custom SVG fonts.
The feature list includes:
- Drawing shapes (ellipse, circle, polyline, polygone, rect, line etc.),
- Drawing gradients (except focus points in radial gradients),
- Drawing path elements, but without markers,
- Drawing text elements, currently working only with standard android fonts,
- Supported such elements as: <g>, <defs>, <use>.
The list of implemented features is not so big, but it is more than enough to paint most of typical SVG files.
SVGHelper: parse and get suitable result
To use this helper, just follow through the list below in top-down order.
- Add “libsvg.aar” in your project.
- Choose SVG source:
- From file:
- From resources (works only with context, useContext(…) is necessary):
- From web:
- Set SVG code directly: SVGHelper.noContext().open(“<svg> any svg source code </svg>”);
- From file:
- Determine SVG document size (if necessary). This option is required if original SVG image has no width/height and viewport attributes.
– define sizes
- Or let library compute itself (if SVG has width/height definition),
Note: might add extra performance penalty.
- Choosing svg transform (if necessary).
Set scale directly: SVGHelper.noContext().open(...).setScale(1.7f);
- Or set result bounds:
- Additional SVG transform options.
- Set keep aspect ratio option (by default true).
- Set crop image option (by default false)
- Choose result type.
- Bitmap as background of any View:
- Picture as stretch background of any View:
A few examples:
- SVG from resource as button background:
- Scaled SVG file as Bitmap:
- SVG from URL, determine its size and get it as 100×100 Bitmap:
Select your license
Below, you can choose any of the available billing plans according to your needs from a free GPL license to an unlimited commercial license.
Can't find what you need? View our custom software development services.
- We provide this library “as is” under the GPLv3.
- Sources: libsvg.zip
- 1 Binary License
- 1 Developer
- Unlimited applications
*volume discounts 25% for 5+ licenses
- 1 Binary license
- Unlimited Developers
- Unlimited applications
- Demo application indicating how long the image is handled at your device (showsvg.apk).
- Sample describing how to load SVG files from different resources (svg_from_different_sources_sample.apk) and source (svg_from_different_sources_sample.zip).
- Sample describing how to use SVG as the background (svgresize_and_background_sample.apk) and source (svgresize_and_background_sample.zip).
- JavaDocs (libsvg-JavaDoc.zip)