Press on the image to return to the main documentation page.
SVG
Written by Andrew Graham
This library supports a subset of the SVG Basic 1.1 specification. Typically, you can just load your vector artwork in a suitable program and then save it as a SVG Basic 1.1 file and it will work fine.
By using vector art, the pain of supporting various screen sizes and densities in Android can be reduced.
These are the features of SVG Basic not supported: Raster images (bitmaps). Symbols, conditional processing. Patterns. Masks, filters and views. Interactivity, linking, scripting and animation.
Bounds and Limits It is useful when working with an SVG to know the rectangular bounds of the content. The document (artboard) bounds themselves are typically not useful for this, as few artists will size the content to those bounds. Instead, we offer two approaches:
Bounds If there is a layer in the artwork called "bounds", it will not be drawn. Rather, the first rectangle found in that layer will be interpreted as the bounds of the artwork. This makes it easy for an artist to specify the right bounds right in the artwork without the developer having to do additional work.
Limits While the parser is reading the SVG, it estimates the bounds of the artwork from what is read. This may not always be correct, but can often be relied upon for simple artwork.
Version 1.0 of this library was a very thin wrapper of the svg-android library which it required as an external component to be referenced as a Lib by Basic4android. svg-android
This version of the library is a very thin wrapper of the svg-android-2 library and the source code for that is compiled into this library so no external component is needed. This fork is used as the original author seems to have not reponded to bug fix requests so another programmer has created this fork and applied some fixes and improvements. Support transforms in g tags Support transform lists (e.g. transform="rotate(..) scale(..) ...") Support for arcs in paths Support implied commands in paths Support for named colors Support for text (limited, but including font-size, type-face, and text alignment) Support for stroke-dasharray for dotted/dashed lines svg-android-2
The svg-android library is released for use under the Apache License Version 2.0. Apache 2.0
Unfotunately the svg-android library is not always very informative about SVG files that it cannot parse. Sometimes it will just throw a NullPointerException without any further information as to where in the SVG file the problem lies. Other times it may throw an exception whose message includes the line and column where the error is located in the SVG data file.
This is a compact and straightforward object for parsing simple SVG files and rendering them in an Android Canvas or as a PictureDrawable that may be assigned to the Background of a View.
Gets the bounding rectangle for the SVG picture data, if one was specified. Returns a Rect object whose parameters are all 0 if no bounding rectangle was specified.
CreateFromStream (istreamAsjava.io.InputStream)
Create a new picture (already recorded) from the data in the stream. This data was generated by a previous call to writeToStream().
Returns an Android PictureDrawable created from the the SVG picture data. This may be assigned to the Background property of a View for display. However DrawPicture may be more useful in practice.
Draw this picture on the specified canvas to fit into the dest rectangle.
HeightAsInt [read only]
Return the height of the rendered SVG picture.
Initialize (dirAsString, filenameAsString)
Initialize the SVG object with a picture obtained from a file name.
Initialize2 (inputstreamAsjava.io.InputStream)
Initialize the SVG object with a picture read from an InputStream.
Initialize3 (svgstringAsString)
Initialize the SVG object with a picture obtained read from an XML string.
IsInitializedAsBoolean
Returns whether a picture exists within the SVG object or not
LimitsAsRectWrapper [read only]
Gets the bounding rectangle for the SVG that was computed upon parsing. It may not be entirely accurate for certain curves or transformations but is often better than nothing. Returns a Rect object.
PictureAsandroid.graphics.Picture [read only]
Returns an Android Picure parsed from the SVG picture data. This is provided in case of need and is not directly usable in Basic4android.
VersionAsDouble [read only]
Returns the version number of the library.
WidthAsInt [read only]
Return the width of the rendered SVG picture.
WriteToStream (ostreamAsjava.io.OutputStream)
Write the picture contents to a stream. The data can be used to recreate the picture by calling createFromStream. Bounds and Limits are not set
Top