图片水印
往图片上加文字
UIImage *oldImage = [UIImage imageNamed:@"1.jpg"];
//上下文
UIGraphicsBeginImageContextWithOptions(oldImage.size, NO, 0.0);
//从零点开始画图
[oldImage drawAtPoint:CGPointZero];
//添加的文字
NSString *text = @"老板,我要加薪!";
//设定字体大小和颜色
NSDictionary *dict = @{NSFontAttributeName:[UIFont systemFontOfSize:38],NSForegroundColorAttributeName:[UIColor redColor]};
//设定要添加字体的位置
[text drawAtPoint:CGPointMake(400, 533) withAttributes:dict];
//得到新的图片
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
//关闭上下文
UIGraphicsEndImageContext();
_headerImageView.image = newImage;
//将生成的新的图片转化为data并
NSData *data = UIImagePNGRepresentation(newImage);
//写到桌面
[data writeToFile:@"/Users/aa/Desktop/Image.jpg" atomically:YES];
图片裁剪
裁剪圆形图片并在圆形周围加一个宽度为5的蓝色圆环
UIImage *oldImage = [UIImage imageNamed:@"4"];
//圆环的宽度
CGFloat borderW = 5;
//大图片的宽度和高度
CGFloat imageW = oldImage.size.width + 2*borderW;
CGFloat imageH = oldImage.size.height + 2*borderW;
//防止有锯齿现象
CGFloat circirW = imageW > imageH ? imageH : imageW;
//开启上下文
UIGraphicsBeginImageContextWithOptions(CGSizeMake(circirW, circirW), NO, 0.0);
//画个大的圆
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0,0, circirW, circirW)];
//获取当前上下文
CGContextRef ctx = UIGraphicsGetCurrentContext();
//添加到上下文
CGContextAddPath(ctx, path.CGPath);
//渲染蓝色
[[UIColor blueColor] set];
//填充
CGContextFillPath(ctx);
//小圆的正切矩形
CGRect clipR = CGRectMake(borderW, borderW, oldImage.size.width, oldImage.size.height);
//画小圆
UIBezierPath *clipPath = [UIBezierPath bezierPathWithOvalInRect:clipR];
//设置裁剪区域
[clipPath addClip];
//画图片
[oldImage drawAtPoint:CGPointMake(borderW, borderW)];
//获取到新的图片
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
//关闭上下文
UIGraphicsEndImageContext();
_headerImage.image = newImage;
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。