How does one serialize a CGContext that contains a modified CGMutablePathRef?
I currently save the context into png representation and serialize this, but it is causing issues with retina display.
I would like to avoid serializing a retina version and resizing it at runtime as this would be inefficient.
If you are just stroking or filling a single path, you can wrap it in a
UIBezierPath, which conforms to theNSCodingprotocol, and then you can serialize theUIBezierPath:Then you can write
datato a file or your database or whatever. Later you can convertdataback to aUIBezierPathand then aCGPath:If you are drawing something more complex than a single path, the easiest way to serialize your drawing in a scalable (vector) format is to draw to a
CGPDFContextinstead of aCGBitmapContext. ACGPDFContextrecords your drawing commands to a PDF. Later, you can create aCGPDFDocumentfor the PDF, and use that to draw the PDF to your bitmap context. Read the PDF Document Creation, Viewing, and Transforming chapter of the * Quartz 2D Programming Guide* for details.