화면에 UIImageView가 있습니다. 여러 색상의 이미지를 표시합니다. 이미지를 클릭하면 이미지의 작은 부분이 자르고 자른 이미지가 새로운 작은 UIImageView로 설정됩니다. 어떤 이유로 인해 자른 이미지가 항상 잘못되었습니다. 여기 UIImage 자르기. 자른 이미지가 올바르지 않음
이 touchesBegin의 전체 코드입니다 : 아래의 스크린 샷을 확인
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint location = [[touches anyObject] locationInView:self.imageView];
UIImage *originalImage = self.imageView.image;
NSLog(@"x = %f, y = %f",location.x,location.y);
CGRect cropRegion = CGRectMake(location.x, location.y, 10, 10);
CGImageRef subImage = CGImageCreateWithImageInRect(originalImage.CGImage, cropRegion);
UIImage *croppedImage = [UIImage imageWithCGImage:subImage scale:originalImage.scale orientation:originalImage.imageOrientation];
[self.previewImageView setImage:croppedImage];
CGImageRelease(subImage);
}
원래 이미지의 크기와 UIImageView의 크기를 비교하면 '위치'의 지점이 터치하는 지점에 없을 가능성이 가장 높습니다. 원시 이미지의 좌표. UIImageView에 맞도록 이미지의 크기가 조정되었을 가능성이 있으므로 올바른 위치를 제공하기 위해 좌표를 조정해야합니다. –