图片水印
1.图片水印即在图片上下文上操作
- 第一:图片上下文不用在drawRect中写,在viewDidLoad中
- 第二:图片上下文需要自己手动创建
- 第三:往后的操作与drawRect的无什么差异
2.具体的看代码分析,将添加文字的那部分去掉,那么就只有图片了。
- (void)viewDidLoad {
[super viewDidLoad];
UIImage *image=[UIImage imageNamed:@"小黄人"];
UIGraphicsBeginImageContextWithOptions(image.size, NO, 0);
[image drawAtPoint:CGPointZero];
NSString *str=@"HYL";
NSMutableDictionary *textDic=[NSMutableDictionary dictionary];
textDic[NSFontAttributeName]=[UIFont systemFontOfSize:30];
textDic[NSForegroundColorAttributeName]=[UIColor redColor];
textDic[NSStrokeWidthAttributeName]=@3;
textDic[NSStrokeColorAttributeName]=[UIColor blueColor];
NSShadow *shade=[[NSShadow alloc]init];
shade.shadowBlurRadius=1;
shade.shadowColor=[UIColor redColor];
shade.shadowOffset=CGSizeMake(2, 2);
textDic[NSShadowAttributeName]=shade;
[str drawAtPoint:CGPointMake(70, 340) withAttributes:textDic];
UIImage *image1=UIGraphicsGetImageFromCurrentImageContext();
self.imageView.image=image1;
}
3.效果图片
- 1.
4.源代码地址