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
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With