th1rdey3
th1rdey3

Reputation: 4358

How to save android Path object as a SVG file?

I have been googling a long time to find a solution on saving an instance of Path class as a SVG file (in a tag. All my searches led me things like "svg-android" which does just the opposite. They parse svg files. However what i want to achieve is to create svg file from Path object. It will be great if someone can point me to the right direction.

Upvotes: 3

Views: 1275

Answers (1)

snowdragon
snowdragon

Reputation: 753

I don't have any code/library for this (yet), but you asked for direction, so here's what I'm thinking of doing for my own project, let me know what you think.

An SVG document with a path is pretty simple to produce, for example:

<html><body>
<svg width="640" height="480" xmlns="http://www.w3.org/2000/svg">
  <g>
     <path class="SamplePath" d="M100,200 C100,100 250,100 250,200
                                   S400,300 400,200" />
  </g>
</svg>
</body></html>

spec: http://www.w3.org/TR/SVG/paths.html

So as you're drawing the path, or perhaps later using the PathMeasure class, just build up the 'd' string attribute of the <path> element.

I haven't tested this yet, but it's a direction :)

Update: I can now confirm this approach worked for me (at least for basic usage).

Upvotes: 2

Related Questions