如何裁剪圆形,方形,三角形中心部分UIImage

时间:2014-10-06 12:43:54

标签: ios objective-c uiimageview

我正在将下面的代码裁剪图像实现为方形

 - (void)imagePickerController:(UIImagePickerController *)picker1 didFinishPickingMediaWithInfo:(NSDictionary *)info {

    tatooImage = [info objectForKey:UIImagePickerControllerOriginalImage];


    UIImageView *imageView = [[UIImageView alloc] initWithImage:tatooImage];

    CGSize size = [tatooImage size];

    [imageView setFrame:CGRectMake(0, 0, size.width, size.height)];

    CGRect rect = CGRectMake(size.width / 4, size.height / 4 ,
                             (size.width / 2), (size.height / 2));



    self.imageOverlay.image =   [self croppedImage:tatooImage cropRect:rect];
   }

- (UIImage *)croppedImage:(UIImage *)image cropRect:(CGRect)cropRect
{
    CGImageRef croppedCGImage = CGImageCreateWithImageInRect(image.CGImage, cropRect);
    UIImage *croppedImage = [UIImage imageWithCGImage:croppedCGImage scale:1.0f orientation:image.imageOrientation];
    CGImageRelease(croppedCGImage);
    return [croppedImage fixOrientation];

}

我面临的问题是我没有获得图像的中心部分

0 个答案:

没有答案