从UIImage

时间:2016-10-11 09:04:04

标签: ios objective-c uiimage crop

我想从UIImage裁剪圆形但不起作用。

enter image description here

这是代码

-(UIImage *)croppedImage {
        UIGraphicsBeginImageContextWithOptions(CGSizeMake(Width(self.cropperImageView), Width(self.cropperImageView)), NO, 0.0);
        CGContextRef context = UIGraphicsGetCurrentContext();
        CGFloat scaleFactorX = Width(self.photoImageView) / self.photoImageView.image.size.width;
        CGFloat scaleFactorY = Height(self.photoImageView) / self.photoImageView.image.size.height;
        CGContextBeginPath(context);
        CGContextAddArc(context, Width(self.cropperImageView) / 2, Width(self.cropperImageView) / 2, Width(self.cropperImageView) / 2, 0, 2 * M_PI, 0);
        CGContextClosePath(context);
        CGContextClip(context);
        CGContextScaleCTM(context, scaleFactorX, scaleFactorY);
        [self.photoImageView.image drawInRect:CGRectMake(Left(self.cropperImageView), Right(self.cropperImageView), Width(self.cropperImageView), Width(self.cropperImageView))];

        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();

        return image;
}

感谢您的提前帮助

0 个答案:

没有答案