- //创建一个UIImage对象
- UIImage *image = [UIImage imageNamed:@"scene1.jpg"];
- //1.建立bitmap Context
- UIGraphicsBeginImageContext(image.size);
- //2.把原图绘制到context上
- [image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
- //3.把水印文字绘制到context上。
- //在左下角加水印
- CGRect textFrame = CGRectMake(0, image.size.height-40, 200, 40);
- //设置水印文字属性
- UIFont *font = [UIFont boldSystemFontOfSize:30];
- NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
- style.alignment = NSTextAlignmentCenter;
-
- UIColor *color = [UIColor colorWithRed:254.0/255 green:201.0/255 blue:21.0/255 alpha:1];
-
- [text drawInRect:textFrame withAttributes:
- @{NSFontAttributeName:font,
- NSForegroundColorAttributeName:color,
- NSParagraphStyleAttributeName:style}];
- //4.从bitmap context上获取加了水印以后的图片。
- UIImage *waterImage = UIGraphicsGetImageFromCurrentImageContext();
- //5.关闭bitmap context。
- UIGraphicsEndImageContext();
- //6.返回获取的图片
- return waterImage;
-
-
- 此方法最好独立成一个单独的类,只需一类方法就能完成。
posted @
2015-04-13 22:01
SilverWinter
阅读(
210)
评论()
编辑
收藏
举报
点击右上角即可分享
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步