사용자 지정 UIBezierPath로 사진을 클리핑 할 때 문제가 있습니다. 대신 경로 내에 영역을 표시하는 대신 사진의 다른 부분을 표시합니다 (그 크기와 위치가 다른 위치와 달라야하지만 그려지는 모양과 동일 함). 참고 원본 사진의 전체 품질을 유지하고 싶습니다.이미지 품질을 유지하면서 사용자 지정 UIBezierPath에 UIImage 잘라 내기
사진과 캡션을 아래에 추가하여 내 문제를 자세히 설명했습니다. 누군가 나에게 그런 일을하는 또 다른 방법을 줄 수 있다면 기꺼이 다시 시작할 것입니다.
은 위 모든 UIBezierPath을 표시하는 CAShapeLayer가 하위 계층으로있는 UIView의 안에있는 UIImageView 내에있는 UIImage의 그림입니다. 이 예제에서는 빨간색으로 표시된 경로가 사용자에 의해 그려 졌다고 가정합니다.
이 다이어그램에는 원본 이미지의 크기로 생성 된 그래픽 컨텍스트와 CAShapeLayer가 나와 있습니다. 어떻게 결과를 생성 할 수 있도록 컨텍스트를 잘라낼 수 있습니까?
이 모든 것이 완료되고 완료 될 때 나는 결과물이되고 싶습니다. 참고 원본과 동일한 크기/품질을 유지하고 싶습니다.
이 클립 이미지 경로
-(UIImage *)maskImageToPath:(UIBezierPath *)path {
// Precondition: the path exists and is closed
assert(path != nil);
// Mask the image, keeping original size
UIGraphicsBeginImageContextWithOptions(self.size, NO, 0);
[path addClip];
[self drawAtPoint:CGPointZero];
// Extract the image
UIImage *maskedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return maskedImage;
}
이것은 UIBezierPath
- (void)drawClippingLine:(UIPanGestureRecognizer *)sender {
CGPoint nextPoint = [sender locationInView:self];
// If UIBezierPath *clippingPath is nil, initialize it.
// Otherwise, add another point to it.
if(!clippingPath) {
clippingPath = [UIBezierPath bezierPath];
[clippingPath moveToPoint:nextPoint];
}
else {
[clippingPath addLineToPoint:nextPoint];
}
UIGraphicsBeginImageContext(_image.size);
[clippingPath stroke];
UIGraphicsEndImageContext();
}
모든 이미지가 기울어졌습니다. 변환을 적용하고 있습니까? 실제 결과를 보여주는 스크린 샷을 보여줍니다. – Wain