tags:

views:

277

answers:

2

Can I write the bytes of a CGPathRef to disk and then read them back later? Is there an easy way to store a SVG style path to disk?

I have a very complicated SVG file (~500K) that I would like to convert into a binary format for easiest storage and loading on the iphone. Looking at the svg file there are only lines and bezier curves all of which map exactly to core graphics path primitives.

Thank you so much,

Carl C-M

+1  A: 

CGPathApply calls a callback for every control point of a CGPathRef.

You can use this to write the control points out to disk.

Rhythmic Fistman
A: 

CGPathElement look like this:

struct CGPathElement {
  CGPathElementType type;
  CGPoint * points;
};

where the element type is an int, and depending on the type there are 2 to 6 floats.

So this can be serialized into to the following

int;float;float;int;float;float;float;float;float;float;

so I look at the first byte, decide the type, get the next n*4 bytes depending on the type, and add it to my path.

I really only need to go from a binary format to paths, but if I needed to convert back, CGPathApply from Rhythmic Fistman would definately be the tool to use.

Carl Coryell-Martin