iOS在照片上添加水印

王朝学院·作者佚名  2016-08-27
窄屏简体版  字體: 小  |  中  |  大  |  超大  

在做项目的时候我们需要将拍摄的照片做上标记防止图片被他人盗用,所以这就需要在照片的上面加上水印,以表示此照片的独一无二。

加水印不是要在上面添加上几个Label,而是我们要把字画到图片上成为一个整体。

提供一个方法 此方法只需要传递一个要加水印的图片和水印的内容就达到效果

1-(UIImage *)watermarkImage:(UIImage *)img withName:(NSString *)name23{45NSString* mark =name;67intw =img.size.width;89inth =img.size.height;1011UIGraphicsBeginImageContext(img.size);1213[img drawInRect:CGRectMake(0,0, w, h)];1415NSDictionary *attr =@{1617NSFontAttributeName: [UIFont boldSystemFontOfSize:20],//设置字体1819NSForegroundColorAttributeName : [UIColor redColor]//设置字体颜色2021};2223[mark drawInRect:CGRectMake(0,10,80,32) withAttributes:attr];//左上角2425[mark drawInRect:CGRectMake(w -80,10,80,32) withAttributes:attr];//右上角2627[mark drawInRect:CGRectMake(w -80, h -32-10,80,32) withAttributes:attr];//右下角2829[mark drawInRect:CGRectMake(0, h -32-10,80,32) withAttributes:attr];//左下角3031UIImage *aimg =UIGraphicsGetImageFromCurrentImageContext();3233UIGraphicsEndImageContext();3435returnaimg;3637}

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航