Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using svg-android library


i'm trying to use svg-android to display a road map i exported from openstreetmap.
I follow the steps from the tutorial and it worked great with a test.svg graphic (3KB). But the exported map is arround 500KB. When i try to load the map i get an SVGParseException:

System.err: com.larvalabs.svgandroid.SVGParseException: java.lang.NumberFormatException
System.err:     at com.larvalabs.svgandroid.SVGParser.parse(Unknown Source)
System.err:     at com.larvalabs.svgandroid.SVGParser.getSVGFromResource(Unknown Source)
System.err:     at my.package.view.SVGMapView.loadSVGImage(SVGMapView.java:141)

line 141 says:

svg = SVGParser.getSVGFromResource(getResources(), R.raw.test);

is there a possibility to preload the svg image in an extra thread, or is there a better solution for my problem?

thanks

like image 996
t0mM3k Avatar asked Jul 11 '11 14:07

t0mM3k


People also ask

Can Android read SVG files?

You can import an SVG file as a VectorDrawable in Android Studio, follow these steps : "Right-click" on the res folder and select new > Vector Asset. Select the Local File option and browse to your . svg file.

Should I use SVG or PNG Android?

Complex images such as screenshots and detailed illustrations should use PNG. While SVGs are harder to create and edit, they have a variety of benefits over PNGs. Whenever it's appropriate to use vector images, such as decorative graphics and logos, definitely use SVG.

Can we use SVG for app icon Android?

If you want to use some icons that are not present in the list of predefined icons, then you can add your own icon by selecting the Asset Type as Local File(SVG, PSD) and then select the path of your file by clicking on Path. After that click on Next > Finish. Now your icon will be added to your res/drawable folder.


1 Answers

What is happening in this case is that the svg library for Android is quite limited, in that it doesn't support the full SVG spec. The map you saved includes some features that svg-android simply can't manage. Unfortunately, there isn't a whole lot you can do about it, except to try a different format.

Threading would not make the problem any better, incidentally. This would make the loading of the image happen in the background, but it would not fix the fundamental problem, that the SVG file simply contains things that can't be parsed.

What you can try is to load the file via an offline SVG tool, and re-save it with the required format, SVG Basic 1.1.

like image 145
PearsonArtPhoto Avatar answered Oct 09 '22 21:10

PearsonArtPhoto