Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying SVG files in Android

Tags:

I want to create an app that will display position on some floor plan. Navigation is implementing via WiFi in certain way, I've done it and so now I have a problem of displaying floor plan.

It might be in some vector format, after surfing internet for some time I've decided that it must be svg file. I found some solutions, but it isn't working for me!

  1. Library svg-android

    There is opportunity to display .svg files, but only "simple" files. It works fine only for file in tutorial, but not for any other .svg file (for example, some other file, that you'll create with Inkscape).

    So, I decided, that I'll parse .svg file, make DOM from it, somehow get objects and attributes and draw it via OpenGL ES.

  2. Apache Batik

    At first glance, very good solution, but there is a problem. Android has some "native" apache libraries and when I try to do something with batik, it throws NoClassDefFoundError, because it's searching not in batik libraries, but in "native" libraries.

    Of course, we can add source code in our project, take only batik parser for .svg files and edit it in some way, but there is a lot of work, with same success we can write our own parser.

  3. Tiny Line

    There is no trial version, but if we'll see description of how it works for svg files and android, we'll see that there is only rasterization of such files and that's all.

Is there any solution better than writing own parser? Did anyone come across this problem?

like image 470
Mary Ryllo Avatar asked Jul 18 '12 06:07

Mary Ryllo


People also ask

Can Android render SVG?

AndroidSVG is a SVG parser and renderer for Android. It has almost complete support for the static visual elements of the SVG 1.1 and SVG 1.2 Tiny specifications (except for filters). AndroidSVG correctly renders the SVG Acid Test.

How do I display SVGs?

How to open an SVG file. From Chrome and Edge to Safari and Firefox, all the major browsers allow you to open SVG files these days — whether you're on a Mac or Windows. Just launch your browser and click on File > Open to choose the file you want to view. It'll then be displayed in your browser.

Does mobile support SVG?

SVG is quite well-supported in mobile browsers. This means that you can link to a SVG file on your page in most mobile browsers and it just works. But… there is one big problem: Android versions under 3 don't have any kind of support for SVG in the stock browser.


1 Answers

I would suggest using #1. Don't write your own parser. It's just going to be a huge headache.

How detailed does your floor plan have to be? android-svg supports SVG fairly well. It just doesn't have great support for filters or light sources. Your SVG isn't going to have those in them (I hope).

If you don't want to do that, look into quad trees. You can render out a huge image and break that down into a quadtree like format then only load the quads you require.

like image 71
Brad Avatar answered Oct 16 '22 21:10

Brad