現(xiàn)在APP界面上都需要將頭像顯示成圓形,調(diào)用以下方法就可以將原始圖片轉(zhuǎn)換成圓形圖片
- (instancetype)gg_circleImage
{
// 1.開啟圖形上下文
// 比例因素:當(dāng)前點(diǎn)與像素比例
UIGraphicsBeginImageContextWithOptions(ggImage.size, NO, 0);
// 2.描述裁剪區(qū)域
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, ggImage.size.width, ggImage.size.height)];
// 3.設(shè)置裁剪區(qū)域;
[path addClip];
// 4.畫圖片
[ggImage drawAtPoint:CGPointZero];
// 5.取出圖片
ggImage = UIGraphicsGetImageFromCurrentImageContext();
// 6.關(guān)閉上下文
UIGraphicsEndImageContext();
}