1
我正在爲iPhone製作一個簡單的繪圖程序。目前,觸摸事件將它們的位置添加到與一系列CGContextAddLineToPoint調用相關聯的列表中,該列表在每次調用drawRect時都會重繪。緩存到CGLayer比iPhone上的重繪要慢
我遇到性能問題,但行數相當少(它們是透明的,但是),所以我嘗試將所有內容都繪製到CGLayer中。現在,不是每一幀都繪製每一行,而是繪製每行一次,並在每一幀繪製CGLayer到屏幕。
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);
這個,如果有的話,比我以前做的要慢。難道我做錯了什麼?我會更好地服務於繪製UIImage或什麼?謝謝。
它看起來好像處理時間的30%是去CGContextStrokePath。 – jonmorgan 2010-07-12 19:40:56
順便提一下,感謝樂器的領導 - 如果你不能說,我對此很新。 – jonmorgan 2010-07-12 19:49:12
謝謝,這解決了這個問題。 – jonmorgan 2010-07-14 15:35:25