iOS在照片上添加水印
2015-08-05 22:07
459 查看
在做项目的时候我们需要将拍摄的照片做上标记防止图片被他人盗用,所以这就需要在照片的上面加上水印,以表示此照片的独一无二。
加水印不是要在上面添加上几个Label,而是我们要把字画到图片上成为一个整体。
提供一个方法 此方法只需要传递一个要加水印的图片和水印的内容就达到效果
<span style="font-size:14px;">-(UIImage *)watermarkImage:(UIImage *)img withName:(NSString *)name
{
NSString* mark = name;
int w = img.size.width;
int h = img.size.height;
UIGraphicsBeginImageContext(img.size);
[img drawInRect:CGRectMake(0, 0, w, h)];
NSDictionary *attr = @{
NSFontAttributeName: [UIFont boldSystemFontOfSize:20], //设置字体
NSForegroundColorAttributeName : [UIColor redColor] //设置字体颜色
};
[mark drawInRect:CGRectMake(0, 10, 80, 32) withAttributes:attr];
[mark drawInRect:CGRectMake(w - 80, 10, 80, 32) withAttributes:attr];
[mark drawInRect:CGRectMake(w - 80, h - 32 - 10, 80, 32) withAttributes:attr];
[mark drawInRect:CGRectMake(0, h - 32 - 10, 80, 32) withAttributes:attr];
UIImage *aimg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return aimg;
}</span>
加水印不是要在上面添加上几个Label,而是我们要把字画到图片上成为一个整体。
提供一个方法 此方法只需要传递一个要加水印的图片和水印的内容就达到效果
<span style="font-size:14px;">-(UIImage *)watermarkImage:(UIImage *)img withName:(NSString *)name
{
NSString* mark = name;
int w = img.size.width;
int h = img.size.height;
UIGraphicsBeginImageContext(img.size);
[img drawInRect:CGRectMake(0, 0, w, h)];
NSDictionary *attr = @{
NSFontAttributeName: [UIFont boldSystemFontOfSize:20], //设置字体
NSForegroundColorAttributeName : [UIColor redColor] //设置字体颜色
};
[mark drawInRect:CGRectMake(0, 10, 80, 32) withAttributes:attr];
[mark drawInRect:CGRectMake(w - 80, 10, 80, 32) withAttributes:attr];
[mark drawInRect:CGRectMake(w - 80, h - 32 - 10, 80, 32) withAttributes:attr];
[mark drawInRect:CGRectMake(0, h - 32 - 10, 80, 32) withAttributes:attr];
UIImage *aimg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return aimg;
}</span>
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- photoshop去除图片上的水印
- WinForm实现为TextBox设置水印文字功能
- C#监控文件夹并自动给图片文件打水印的方法
- PHP根据图片色界在不同位置加水印的方法
- asp水印组件之AspJpeg的结合代码实例
- C#给图片加水印的简单实现方法
- js判断客户端是iOS还是Android等移动终端的方法
- IOS开发环境windows化攻略
- .net平台推送ios消息的实现方法
- PHP 使用 Imagick 裁切/生成缩略图/添加水印自动检测和处理 GIF
- C#(.net)水印图片的生成完整实例
- 探讨Android与iOS,我们将何去何从?
- Android、iOS和Windows Phone中的推送技术详解