#####裁切圖片(圓頭像的實現) #####1.仍是那幾個步驟git
#####2.步驟詳細在代碼裏github
- (void)viewDidLoad { [super viewDidLoad]; //加載圖片 UIImage *image=[UIImage imageNamed:@"阿狸頭像"]; //開啓圖片上下文 UIGraphicsBeginImageContextWithOptions(image.size, NO, 0); //裁切 //裁切範圍 //如下兩種方法均可以 UIBezierPath *path=[UIBezierPath bezierPathWithArcCenter:CGPointMake(image.size.width*0.5, image.size.height*0.5) radius:image.size.width*0.5 startAngle:0 endAngle:M_PI*2 clockwise:YES]; // UIBezierPath *path=[UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, image.size.width, image.size.height)]; [path addClip]; //[path fill]; //繪製圖片 [image drawAtPoint:CGPointZero]; //從上下文中得到裁切好的圖片 UIImage *image1=UIGraphicsGetImageFromCurrentImageContext(); //關閉圖片上下文 UIGraphicsEndImageContext(); //顯示 self.imageView.image=image1; }
#####3.效果圖片.net
#####4.源代碼的地址code