#####图片水印 #####1.图片水印即在图片上下文上操做git
#####2.具体的看代码分析,将添加文字的那部分去掉,那么就只有图片了。github
- (void)viewDidLoad { [super viewDidLoad]; //加载图片 UIImage *image=[UIImage imageNamed:@"小黄人"]; //建立上下文,以后与drawRect同样的操做 //opaque:不透明度,不透明 Yes //scale:取值为0不缩放 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; //// UIColor, default nil: same as foreground color 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.效果图片.net
#####4.源代码地址code