iOS中的图像裁剪和圆形格式缩放

时间:2015-01-02 06:06:55

标签: ios objective-c iphone uiimageview uiimage

enter image description here

这里我试图缩放裁剪区域并试图以圆形格式进行掉落区域,但我没有得到适当的解决方案。那么请帮帮我,有人知道吗?

CALayer* layer = self.blurredImageView.layer;
UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0);
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextAddRect(c, self.cropArea);
CGContextAddRect(c, rect);
CGContextEOClip(c);
CGContextSetFillColorWithColor(c, [UIColor blackColor].CGColor);
CGContextFillRect(c, rect);
UIImage* maskim = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

2 个答案:

答案 0 :(得分:1)

GitHub上有一个现成的库,用于圆形裁剪,例如iOS的默认联系人应用程序。这可能对您有所帮助。

答案 1 :(得分:0)

您只需将UIImageView的圆角半径设置为其宽度的一半。

像:

imgHspt.layer.cornerRadius = imgHspt.frame.size.width/2.0f;
imgHspt.layer.borderWidth = 0.5f;
imgHspt.clipsToBounds = YES;
imgHspt.layer.masksToBounds = YES;

这适用于每个图像。 希望它有效。