SVG转换 - 存储路径,油漆和Matrix对象有效的方法? [英] SVG conversion - efficient way to store Path, Paint and Matrix objects?

查看:140
本文介绍了SVG转换 - 存储路径,油漆和Matrix对象有效的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Andr​​oid应用我已经创建了一个SVG图像转换器类。它分析通过SVG XML数据,并将其转换成,然后可以施加到帆布适当路径,油漆和Matrix对象。使用这个类我已经再实现一个视图,它使用我的SVG转换器类来绘制,我在屏幕上产生Inkscape中的图像。到目前为止,一切都很好。 (即写我自己的SVG转换器我AP preciate可以考虑车轮考虑它已经做过的再创造,但对我来说这是我的第一个Android应用程序非常有用的练习,并应希望给我一些额外的灵活性。)

In my Android application I have created an SVG image converter class. It parses through the SVG XML data and converts it into the appropriate Path, Paint and Matrix objects which can then be applied to the Canvas. Using this class I have then implemented a View which uses my SVG converter class to draw images I've produced in Inkscape on the screen. So far, so good. (I appreciate that writing my own SVG converter could be considered reinvention of the wheel considering it's been done before, but for me it's a useful learning exercise in my first Android application, and shall hopefully give me some extra flexibility.)

使用SVG的目的是为了让我能快速,轻松地创作图形计的各种设计。每个计通常由图形,只需要一次绘制(如轨距面和传说),加上显卡部分,它会定期更新(指针角,数值文本)。

The purpose of using SVG is so that I can quickly and easily author various designs of graphical gauge. Each gauge typically consists of a section of graphics which only need to be drawn once (e.g. the gauge face and legends), plus graphics which are regularly updated (pointer angle, numeric value text).

在present我限界角度也不是很有效的,因为每一次的OnDraw()被调用时,我SVG类称为整个SVG文件脆裂,产生的所有矢量数据的画布。

At present my gauge View is not very efficient because every time onDraw() is called, my SVG class is called to rattle through the entire SVG file to produce all the vector data for the Canvas.

我想这样做是有矢量数据,以便SVG XML文件只需要进行一次分析的一些中间存储。所以,我在想,在视图可以从第一的OnDraw()SVG文件懒惰初始化自身,然后存储所有生成的路径的,漆和Matrix对象,以各种列表。然后,在每个后续的OnDraw(),我刚拉出来的那些名单(S),并滔滔不绝通过这些到画布上。

What I would like to do is to have some intermediate storage of the vector data so that the SVG XML file only need be parsed once. Therefore, I was thinking that the View could lazy-initialize itself from the SVG file on the first onDraw() and then store all of the resulting Paths, Paint and Matrix objects to various Lists. Then, on each subsequent onDraw(), I just pull those out of the List(s) and rattle through those onto the Canvas.

这方面的一个进一步的优点是使用单独的解释来存储的矢量图形被移动的部分,如压力表指针。我想通过分配一定的魔力的ID,以本集团内重新present指针在Inkscape中的路径这样做的; SVG的解析器类然后将认识到,这种独立的组需要单独存储到仍然是图形。于是,每当我需要刷新指针的角度,根据测量数据,该视图将只应用于旋转变换到一堆矢量数据。其实,我想这样做,使移动指针图形实际上是绘制子视图,这样当指针被刷新刚子视图是重绘的。

A further advantage of this would be to use separate Lists to store sections of vector graphics that are "moving", e.g. the gauge pointer. I thought of doing this by assigning a certain 'magic' ID to the group of paths in Inkscape that represent the pointer; the SVG parser class would then recognise that this separate group needs to be stored separately to the 'still' graphics. Then, whenever I need to refresh the angle of the pointer in accordance to measurement data, the View will only apply the rotational transform to that bunch of vector data. In fact, I'm thinking of doing it so that the moving pointer graphics are actually drawn in a child View, so that just the child View is redrawn when the pointer has to be refreshed.

这一切的最终目标是这样的:我(甚至用户)可以启动一个矢量成像程序像Inkscape中,并快速生成仪表部件的新设计。余嵌入位的元数据来指示所述图形的位必须根据测量数据进行操作。

The end objective of all of this is this: I (or perhaps even users) could fire up a vector imaging program like Inkscape and quickly produce a new design of gauge widget. I embed a bit of metadata to indicate which bits of the graphics have to be manipulated according to measurement data.

而不是寻求一个解决一个问题,因为这样,我想听到什么,我在这里做的意见,无论是什么,我建议可以以更优化的方式来完成。难道是非常记忆低效的路径和油漆的对象缓存组?

Rather than asking for a solution to a problem as such, I'd like to hear opinions about what I'm doing here, and whether what I'm proposing could be done in a much more optimised way. Could it be very memory inefficient to cache groups of Path and Paint objects?

此外,一旦它不够好(!)我会很乐意的地方发表我的SVG类,如果任何人都会觉得它有用。

Furthermore, once it's good enough(!) I'll gladly publish my SVG class somewhere if anyone would find it useful.

推荐答案

执行和衡量! 先从简单的方法 - 存储你的解析矢量数据列表在内存中。如果内存使用和渲染速度是可以接受的:问题就迎刃而解了。 如果没有,请尝试其他的东西和措施。一些想法:

Implement and measure! Start with the straightforward approach--store your parsed vector data in lists in memory. If memory usage and rendering speed is acceptable: problem solved. If not, try other things and measure. Some ideas:

  • 解析SVG一次,一次渲染位图,再用位图
  • 在渲染SVG作为构建过程的一部分,船舶光栅位图与应用

除了简单的情况下,我们是不是很好的assesing如何有效的一种特殊的技术将是。因此,流行的说法是的 premature优化是万恶之源的。

Except for the simplest cases, we're not very good with assesing how effective a particular technique is going to be. Thus the popular saying that premature optimization is root of all evil.

这篇关于SVG转换 - 存储路径,油漆和Matrix对象有效的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆