Note that there are some explanatory texts on larger screens.

plurals
  1. POCaching to CGLayer slower than redrawing on iPhone
    text
    copied!<p>I'm in the process of making a simple drawing program for the iPhone. At the moment, touch events add their location to a list which is connected with a bunch of CGContextAddLineToPoint calls which are redrawn in every call to drawRect.</p> <p>I'm running into performance issues at fairly low numbers of lines (they are transparent, though), so I tried drawing everything into a CGLayer. Now, instead of drawing each line every frame, it draws each line only once and draws the CGLayer to the screen every frame.</p> <pre><code> CGContextRef backgroundContext = CGLayerGetContext(pathBuffer); CGContextSetLineWidth(backgroundContext, 2.0); CGContextSetLineCap(backgroundContext, kCGLineCapButt); CGContextSetStrokeColorWithColor(backgroundContext, [pathColor CGColor]); if([[touchPoints objectAtIndex:0] continuesToNextPoint]) { CGContextMoveToPoint(backgroundContext, [[touchPoints objectAtIndex:0] point].x, [[touchPoints objectAtIndex:0] point].y); CGContextAddLineToPoint(backgroundContext, [[touchPoints objectAtIndex:1] point].x, [[touchPoints objectAtIndex:1] point].y); CGContextStrokePath(backgroundContext); } //remove it from touchpoints [touchPoints removeObjectAtIndex:0]; } CGContextRef context = UIGraphicsGetCurrentContext(); CGContextDrawLayerAtPoint(context, CGPointMake(0, 0), pathBuffer); </code></pre> <p>This, if anything, is SLOWER than what I was doing before. Am I doing something wrong? Would I be better served drawing to a UIImage or something? Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload