- (void)viewDidLoad {
[super viewDidLoad];
//加载图片
UIImage *image = [UIImage imageNamed:@"菲哥"];
//获取图片尺寸
CGSize size = image.size;
//开启位图上下文
UIGraphicsBeginImageContextWithOptions(size, NO, 0);
//创建圆形路径
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
//设置为裁剪区域
[path addClip];
//绘制图片
[image drawAtPoint:CGPointZero];
//获取裁剪后的图片
_imageView.image = UIGraphicsGetImageFromCurrentImageContext();
//关闭上下文
UIGraphicsEndImageContext();
}
- (void)viewDidLoad {
[super viewDidLoad];
//加载图片
UIImage *image = [UIImage imageNamed:@"大菲哥"];
//设置边框宽度
CGFloat border = 3;
CGFloat imageWH = image.size.width;
//计算外圆的尺寸
CGFloat ovalWH = imageWH + 2 * border;
//开启上下文
UIGraphicsBeginImageContextWithOptions(image.size, NO, 0);
//画一个大的圆形
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, ovalWH, ovalWH)];
[[UIColor orangeColor]set];
[path fill];
//设置裁剪区域
UIBezierPath *path1 = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(border, border, imageWH, imageWH)];
[path1 addClip];
//绘制图片
[image drawAtPoint:CGPointMake(border, border)];
//从上下文中获取图片
_imageView.image = UIGraphicsGetImageFromCurrentImageContext();
//关闭上下文
UIGraphicsEndImageContext();
}
- (void)viewDidLoad {
[super viewDidLoad];
//开启上下文
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, 0);
//获取上下文
CGContextRef ctx = UIGraphicsGetCurrentContext();
//把控件上的图层渲染到上下文
[self.view.layer renderInContext:ctx];
//获取上下文中的图片
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
//关闭上下文
UIGraphicsEndImageContext();
//保存图片到相册
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有