iPad의 drawRect 메서드에서 코코아보기로 여러 CGPaths
을 그리는 중입니다. UIGraphicsGetCurrentContext()
컨텍스트로 바로 그리기 시작했지만 내 경로가 길어질수록 성능이 떨어졌습니다. several 다른 질문에 기초하여 CGLayer
초를 조사하기 시작했습니다.CGLayer 및 앤티 앨리어스가 적용된 CGPath
그럼 이제는 경로를 렌더링하는 것입니다. CGContextRef
CGLayerGetContext
을 호출합니다.
// rect comes from the drawRect: method
layer = CGLayerCreateWithContext(context, rect.size, NULL);
layerContext = CGLayerGetContext(layer);
CGContextSetLineCap(layerContext, kCGLineCapRound);
// Set the line styles
CGContextSetLineJoin(layerContext, kCGLineJoinRound);
CGContextSetLineWidth(layerContext, 1.0);
CGContextSetStrokeColorWithColor(layerContext, [UIColor blackColor].CGColor);
// Create a mutable path
path = CGPathCreateMutable();
// Move to start point
//...
for (int i = 0; i < points.count; i++) {
// compute controlPoint and anchorPoint
//...
CGPathAddQuadCurveToPoint(path,
nil,
controlPoint.x,
controlPoint.y,
anchorPoint.x,
anchorPoint.y);
}
// Stroke the path
CGContextAddPath(layerContext, path);
CGContextStrokePath(layerContext);
// Add the layer to the main context
CGContextDrawLayerAtPoint(context, CGPointZero, layer);
지금, 나는 좋은 성능의 도면을 얻을 수 있지만, 내 라인은 매우 들쭉날쭉하고 안티 앨리어싱 될 것 같지 않습니다 여기에 내가 뭘하는지의 기본적인 개요입니다. 나는 위의 코드에 아무런 소용이 없다.
을 추가하려고 시도했다. 나는 심지어 주 context
에서 앤티 앨리어싱 속성을 변경하지 않고 설정했습니다. 동일한 코드 결과의 스크린 샷을 찍었지만 두 번째 이미지는 드로잉에서 생성 된 이미지 인 CGLayer
입니다. 보시다시피, 똑같은 코드 임에도 불구하고 실제로는 들쭉날쭉 해져 있으며 layerContext
으로 그려져 있습니다. CGLayer
의 라인을 부드럽게하려면 어떻게해야합니까?
안녕하세요, @Streeter, 나는 또한 CgLayer isssue와 붙어있어 CgLayer로 그릴 수있는 방법을 생각할 수 없다, 내가 이것에 관한 질문을 게시했습니다, 당신은 제발 http://jackleflow.com/questions/보세요 11341763/how-to-use-cglayer-for-optimal-drawing – Ranjit