美文网首页
为照片添加水印效果的实现

为照片添加水印效果的实现

作者: pinksnow | 来源:发表于2016-07-25 10:14 被阅读51次

主要用时验证照片的真实性 以及照片版权等类信息

+(UIImage)YHWaterMarkImage:(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:13],  //设置字体

NSForegroundColorAttributeName : [UIColor cyanColor]  //设置字体颜色

};

[mark drawInRect:CGRectMake(0, img.size.height-20,img.size.width  ,20) withAttributes:attr];

UIImage *aimg = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return aimg;

}

第一个参数传当前获取到的照片UIImage

第二个参数就是你想添加的水印字段

这边我个人添加的是系统当前时间(NSDate)

效果图如下

相关文章

网友评论

      本文标题:为照片添加水印效果的实现

      本文链接:https://www.haomeiwen.com/subject/tpugjttx.html