iOS在照片上添加水印

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

加水印不是要在上面添加上几个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>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值