2014-02-16 4 views
2

Mac의 CoreAnimation에서 CALayer의 "실제 픽셀 경계"또는 "마스크 경로"인 베 지어 경로를 얻을 수있는 방법이 있습니까?변환되지 않은 좌표에서 CALayer의 "마스크 경로"가져 오기

예를 들어 사진의 콘텐츠, 1 픽셀의 흰색 경계 및 X 및 Y 회전 변환으로 설정된이 CALayer가 있습니다. 변형이 적용된 상태에서 픽셀의 경로를 유도하는 방법이 있습니까?

예 이미지 : 내 요구에이 작업을 수행하는 방법을 알아 냈

enter image description here

답변

0

. 진정한 "마스크 경로"는 아니지만 인수 레이어의 좌표 공간에서 변형 된 사각형의 경로이며 실제로 필요한 것입니다.

- (NSBezierPath*)layerPathConvertedToLayer:(CALayer*)toLayer 
{ 
    CGRect bounds = self.bounds; 
    CGPoint topLeft = CGPointMake(NSMinX(bounds), NSMinY(bounds)); 
    CGPoint topRight = CGPointMake(NSMaxX(bounds), NSMinY(bounds)); 
    CGPoint bottomRight = CGPointMake(NSMaxX(bounds), NSMaxY(bounds)); 
    CGPoint bottomLeft = CGPointMake(NSMinX(bounds), NSMaxY(bounds)); 

    CGPoint convertedTopLeft = [self convertPoint:topLeft toLayer:toLayer]; 
    CGPoint convertedTopRight = [self convertPoint:topRight toLayer:toLayer]; 
    CGPoint convertedBottomRight = [self convertPoint:bottomRight toLayer:toLayer]; 
    CGPoint convertedBottomLeft = [self convertPoint:bottomLeft toLayer:toLayer]; 

    NSBezierPath *bezierPath = [NSBezierPath bezierPath]; 
    [bezierPath moveToPoint:convertedTopLeft]; 
    [bezierPath lineToPoint:convertedTopRight]; 
    [bezierPath lineToPoint:convertedBottomRight]; 
    [bezierPath lineToPoint:convertedBottomLeft]; 
    [bezierPath lineToPoint:convertedTopLeft]; 
    [bezierPath closePath]; 

    return bezierPath; 
} 
:

이 방법의 문맥에서의 CALayer 범주이며