1.图片裁剪
//开启图形上下文
UIGraphicsBeginImageContextWithOptions(topic.pictureF.size, YES, 0.0);
//将下载完的Image对象绘制到图形上下文
CGFloat width = topic.pictureF.size.width;
CGFloat height = width * image.size.height/image.size.width;
[image drawInRect:CGRectMake(0, 0, width, height)];
//获得图片
self.imageView.image = UIGraphicsGetImageFromCurrentImageContext();
//结束图形上下文
UIGraphicsEndImageContext();
2.正方形图片设置圆角(比在图层layer要高效,不会出现卡顿,layer设置圆角会出现卡顿现象)
//开启图形上下文
UIGraphicsBeginImageContextWithOptions(self.size, NO, 0.0);
//获得上下文
CGContextRef ctx = UIGraphicsGetCurrentContext();
//添加一个圆
CGRect rect = CGRectMake(0, 0, self.size.width, self.size.height);
CGContextAddEllipseInRect(ctx, rect);
//裁剪
CGContextClip(ctx);
//将图片画上去
[self drawInRect:rect];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
//结束
UIGraphicsEndImageContext();