CGContext

Unfiled

 * http://omgili.com/cgcontextref-context
 * http://stackoverflow.com/questions/2033321/cgcontextsetlinewidthcontext-1-the-width-is-almost-alwayas-at-least-2-pixels
 * http://developer.apple.com/graphicsimaging/pythonandquartz.html
 * http://stackoverflow.com/questions/2622390/what-way-to-use-the-cgcontext-to-draw-is-suitable


 * Main object type is a CGContextRef, not a CGContext*
 * A CGContext represents a canvas
 * As a rule of thumb, leave the canvas in the same state as when you found it
 * Standard form is to
 * get a ref
 * save its state
 * reset the internal matrix
 * do something with it
 * draw and then
 * restore the ref back to the original state

- (void)drawRect:(CGRect)rect { // Get and save a graphics context CGContextRef context = UIGraphicsGetCurrentContext; CGContextSaveGState(context); // Reset the transformation CGAffineTransform to = CGContextGetCTM(context); to = CGAffineTransformInvert(to); CGContextConcatCTM(context, to);

// Draw a green rect CGContextBeginPath(context); CGContextSetRGBFillColor(context, 0, 1, 0, 1); CGContextAddRect(context, CGRectMake(0, 0, 100, 100)); CGContextClosePath(context); CGContextDrawPath(context, kCGPathFill);

// Cleanup CGContextRestoreGState(context); }


 * Multiplying a matrix by its inverse returns the identity matrix

Resources

 * Beginning iPhone Games Development
 * Quartz 2D - Transforms
 * http://www.iphonedevsdk.com/forum/iphone-sdk-development/12208-cgcontext-drawing-text-custom-view.html
 * http://forums.macrumors.com/showthread.php?t=925312
 * http://stackoverflow.com/questions/913470/iphone-sdk-how-do-you-measure-the-width-and-height-of-a-string-using-quartz
 * http://developer.apple.com/mac/library/samplecode/TextSizingExample/Listings/FieldAspect_h.html#//apple_ref/doc/uid/DTS40008841-FieldAspect_h-DontLinkElementID_5
 * http://trailsinthesand.com/exploring-iphone-graphics-part-1/
 * http://www.iphonedevsdk.com/forum/iphone-sdk-development/8314-display-text-using-quartz.html
 * Rotating NSString
 * http://svn.red-bean.com/pyobjc/trunk/pyobjc/pyobjc-framework-Quartz/Examples/Programming%20with%20Quartz/BasicDrawing/QuartzTextDrawing.py
 * http://stackoverflow.com/questions/3440825/does-cgcontextsettextmatrix-work-for-offscreen-bitmaps
 * http://stackoverflow.com/questions/1895818/how-do-i-use-cgaffinetransformmakescale-and-rotation-at-once
 * http://stackoverflow.com/questions/216076/uiview-scale-to-0-using-cgaffinetransformmakescale

Drawing
"I have to render a path with one color, before I draw a path with another color"
 * http://stackoverflow.com/questions/3041776/iphone-cgcontext-drawing-two-lines-with-two-different-colors
 * http://stackoverflow.com/questions/1943325/how-do-i-stroke-a-cgcontext-path-with-multiple-random-images

Pie Chart
"The UIKit framework includes UIGraphics.h which declares: UIGraphicsGetCurrentContext which, when you call it inside your drawRect: ovverride returns the current CGContextRef Once you have that, you can use the CoreGraphics framework's CGPathAddArc to add a wedge of a circle to a CGPath, then CGContextFillPath or CGContextStrokePath to actually draw the path. Use CGPathCreateMutable to make it, and CGPathRelease when you are done.""If you want to copy the drawing into an image, save the current content create a CGBitmapContext, make it current, do your drawing there, then convert that to a UIImage using imageWithCGImage: (then restore the CGContext, and release the CGBitmapContext )"
 * http://www.google.com.af/support/forum/p/Google+Mobile/user?userid=10632020958419185067&hl=en