iOS图片设置圆角

 1 + (UIImage *)imageWitCornerRadius:(float)cornerRadius image:(UIImage *)original
 2 {
 3     CGRect frame = CGRectMake(0, 0, original.size.width, original.size.height);
 4     UIGraphicsBeginImageContextWithOptions(original.size, NO, 1.0);
 5     
 6     [[UIBezierPath bezierPathWithRoundedRect:frame cornerRadius:cornerRadius] addClip];
 7     [original drawInRect:frame];
 8     
 9     UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
10     UIGraphicsEndImageContext();
11     
12     return image;
13 }

//图片压缩

1 + (UIImage *)scaleToSize:(UIImage *)img size:(CGSize)size{
2     UIGraphicsBeginImageContext(size);
3     [img drawInRect:CGRectMake(0, 0, size.width, size.height)];
4     UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
5     UIGraphicsEndImageContext();
6     return scaledImage;
7 }

 

posted @ 2017-02-27 09:33  福泽小院  阅读(164)  评论(0编辑  收藏  举报