在 Android 中显示 SVG 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11535780/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Displaying SVG files in Android
提问by Mary Ryllo
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.
我想创建一个应用程序来显示某个平面图上的位置。导航正在以某种方式通过 WiFi 实现,我已经完成了,所以现在我在显示平面图时遇到了问题。
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!
它可能是某种矢量格式,在网上冲浪一段时间后我决定它必须是 svg 文件。我找到了一些解决方案,但它对我不起作用!
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.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.There is no trial version, but if we'll see descriptionof how it works for svg files and android, we'll see that there is only rasterization of such files and that's all.
有机会显示 .svg 文件,但只能显示“简单”文件。它仅适用于教程中的文件,但不适用于任何其他
.svg
文件(例如,您将使用 Inkscape 创建的其他文件)。所以,我决定,我将解析
.svg
文件,从中创建 DOM,以某种方式获取对象和属性并通过 OpenGL ES 绘制它。乍一看,很好的解决方案,但有一个问题。Android 有一些“原生”apache 库,当我尝试用蜡染做一些事情时,它抛出
NoClassDefFoundError
,因为它不是在蜡染库中搜索,而是在“原生”库中搜索。当然,我们可以在我们的项目中添加源代码,只对
.svg
文件使用蜡染解析器并以某种方式对其进行编辑,但是有很多工作,同样成功我们可以编写我们自己的解析器。没有试用版,但如果我们看到它如何用于 svg 文件和 android 的描述,我们将看到只有这些文件的光栅化,仅此而已。
Is there any solution better than writing own parser? Did anyone come across this problem?
有没有比编写自己的解析器更好的解决方案?有没有人遇到过这个问题?
采纳答案by Brad
I would suggest using #1. Don't write your own parser. It's just going to be a huge headache.
我建议使用#1。不要编写自己的解析器。这将是一个巨大的头痛。
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).
您的平面图必须有多详细?android-svg 对 SVG 的支持相当好。它只是对过滤器或光源没有很好的支持。你的 SVG 不会有那些(我希望)。
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.
如果您不想这样做,请查看四叉树。您可以渲染一个巨大的图像并将其分解为类似四叉树的格式,然后只加载您需要的四边形。
回答by siliconeagle
I have authored an SVG libaray for android the website is http://www.vectoroid.com
我为 android 编写了一个 SVG libaray,网站是 http://www.vectoroid.com
the main thing missing is SVG arc support this is currently fixed and will be in a release in the near future.
缺少的主要内容是 SVG arc 支持,目前已修复,将在不久的将来发布。
I am looking for feedback on it, as i have been working on it for about a year. So if you have any please do tell ...
我正在寻找有关它的反馈,因为我已经为此工作了大约一年。所以如果你有的话请告诉...
回答by Victor
I've using yet another SVG for Android; seems it is relatively new.
GPLv3, CSS2 support, fonts, texts and spans, linear and radial gradients, SVG and SVGZ, initial filtering support, images from assets, from web and inline base64-encoded images. Fastest from all I've tried.
GPLv3、CSS2 支持、字体、文本和跨度、线性和径向渐变、SVG 和 SVGZ、初始过滤支持、来自资产的图像、来自 Web 和内联 base64 编码图像。我尝试过的最快的。
Of course filters support might be better, but except this it works well and even displays 20-megabytes SVG files.
当然过滤器支持可能会更好,但除此之外它运行良好,甚至可以显示 20 兆字节的 SVG 文件。