#####圖片水印 #####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