0

자르기 기능을 구현 중이며 자르기 사각형이 변환 된 이미지보기 안에 완전히 포함되어 있는지 테스트하는 방법을 알아 내려고하고 있습니다. 즉, 이미지의 잘린 부분에 공백이 없어야한다.CGRect가 다른 (변형 된) 사각형 안에 포함되어 있는지 확인하십시오.

비슷한 구성 (아래 참조)을 구현하는 https://github.com/heitorfr/ios-image-editor이이 구성 요소에서 구현 된 동작을 복사하려고했지만 상황에 따라 작동하지 않습니다.

- (void)checkBoundsWithTransform:(CGAffineTransform)transform 
{ 
    CGRect r1 = [self boundingBoxForRect:self.preview.cropRect 
         rotatedByRadians:[self imageRotation]]; 
    Rectangle r2 = [self applyTransform:transform 
           toRect:self.preview.initialImageFrame]; 

    CGAffineTransform t = 
    CGAffineTransformMakeTranslation(CGRectGetMidX(self.preview.cropRect), 
             CGRectGetMidY(self.preview.cropRect)); 
    t = CGAffineTransformRotate(t, -[self imageRotation]); 
    t = CGAffineTransformTranslate(t, 
            -CGRectGetMidX(self.preview.cropRect), - 
            CGRectGetMidY(self.preview.cropRect)); 

    Rectangle r3 = [self applyTransform:t toRectangle:r2]; 

    if(CGRectContainsRect([self CGRectFromRectangle:r3],r1)) { 
     self.validTransform = transform; 
    } 
} 
+0

중복 가능성 (http://stackoverflow.com/questions/8981931/cgrectcontainsrect-not-working) – Palpatim

+1

이는, CGRectContainsRect() 해결 될 수있는 문제가 아니다 이미지 뷰의 변형 된 사각형을 회전시킬 수 있습니다. 즉, CGRect – Niels

답변

1

가장 성능이 뛰어난 솔루션은 아니지만 매우 빠르고 더러운 것입니다.

NSBezierPath *path = [NSBezierPath bezierPathWithRect:r2]; 
[path transformUsingAffineTransform:t]; 
if([path containsPoint:NSMinX(r1)] 
    && [path containsPoint:NSMinY(r1)] 
    && [path containsPoint:NSMaxX(r1)] 
    && [path containsPoint:(NSMaxY(r1)]){ 
    self.validTransform = transform; 
} 
[CGRectContainsRect 작동하지 않음]의
+0

으로 표현할 수 없습니다. NSBezierPath (또는 내 경우에는 UIBezierPath)를 사용하지 않을 생각이었습니다. 좋은 생각, 고마워! – Niels

관련 문제