//1.加载要添加水印的图片
UIImage * image = [UIImage imageNamed:@"img05"];
//2.开启一个和图片大小相同的图形上下文对象 (bitmap)
UIGraphicsBeginImageContextWithOptions(image.size, NO, 0.0);
//3.绘制图片
[image drawAtPoint:CGPointZero];
//4.添加文字水印
NSString * str = @"美人你一直是我的春天,你是我生命中的世外桃源";
NSDictionary * atts = @{
NSFontAttributeName:[UIFont systemFontOfSize:25.f],
NSForegroundColorAttributeName:[UIColor redColor]
};
[str drawInRect:CGRectMake(200, 500, 300, 200) withAttributes:atts];
//5.添加图片水印
UIImage * logoImage = [UIImage imageNamed:@"logo"];
[logoImage drawAtPoint:CGPointMake(300, 900)];
//6.从图形上下文中获取图片
UIImage * getImage = UIGraphicsGetImageFromCurrentImageContext();
//7.结束图形上下文
UIGraphicsEndImageContext();
//8.使用图片
UIImageWriteToSavedPhotosAlbum(getImage, nil, nil, nil);
网友评论