【发布时间】:2012-08-05 06:58:23
【问题描述】:
对我之前的结果不满意,我被要求创建一个在缩放时不会模糊的手绘视图。我能想到的唯一方法是使用CATiledLayer,否则在缩放时画线太慢了。目前,我已将其设置为每次都会重绘每一行,但我想知道我是否可以缓存前几行的结果(not 为像素,因为它们需要很好地缩放)在上下文或某事中。
我考虑过 CGBitmapContext,但这是否意味着我需要在每次缩放后拆除并设置一个新的上下文?问题是在视网膜显示器上,线条绘制太慢(在 iPad 2 上是马马虎虎),尤其是在缩放时绘制。 App Store 中有一个叫 GoodNotes 的应用程序,它精美地证明了这是可能的,并且可以顺利完成,但我无法理解他们是如何做到的。这是我到目前为止的代码(今天大部分时间的结果):
- (void)drawRect:(CGRect)rect
{
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(c, mLineWidth);
CGContextSetAllowsAntialiasing(c, true);
CGContextSetShouldAntialias(c, true);
CGContextSetLineCap(c, kCGLineCapRound);
CGContextSetLineJoin(c, kCGLineJoinRound);
//Protect the local variables against the multithreaded nature of CATiledLayer
[mLock lock];
NSArray *pathsCopy = [mStrokes copy];
for(UIBezierPath *path in pathsCopy) //**Would like to cache these**
{
CGContextAddPath(c, path.CGPath);
CGContextStrokePath(c);
}
if(mCurPath)
{
CGContextAddPath(c, mCurPath.CGPath);
CGContextStrokePath(c);
}
CGRect pathBounds = mCurPath.bounds;
if(pathBounds.size.width > 32 || pathBounds.size.height > 32)
{
[mStrokes addObject:mCurPath];
mCurPath = [[UIBezierPath alloc] init];
}
[mLock unlock];
}
Profiling 显示目前最热门的函数是 GCSFillDRAM8by1
【问题讨论】:
标签: ios core-graphics vector-graphics catiledlayer