我想从UIImage
裁剪圆形但不起作用。
这是代码
-(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;
}
感谢您的提前帮助