Quartz2D-图片添加水印

来源:互联网 发布:里约中国男篮数据 编辑:程序博客网 时间:2024/04/28 20:54

如图在图片上添加水印 大体流程就是自己获取一个上下文将图片和文字和图片绘制到上下文当中;然后生成一张新的图片


      //需要添加水印的图片    UIImage *image = [UIImage imageNamed:@"阿狸头像"];        //1.开启一个跟图片原始大小的上下文    UIGraphicsBeginImageContextWithOptions(image.size, NO, 0);        //2.将图片绘制到上下文当中    [image drawAtPoint:CGPointZero];        //3.将文字绘制到上下文当中    NSString *str = @"版权所有";    NSMutableDictionary *dic = [NSMutableDictionary dictionary];    dic[NSFontAttributeName] = [UIFont systemFontOfSize:18];    dic[NSForegroundColorAttributeName] = [UIColor blueColor];    [str drawAtPoint:CGPointMake(image.size.width - 75, image.size.height - 20) withAttributes:dic];        //4.从上下文当中生成一张图片    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();        //5.关闭山下文    UIGraphicsEndImageContext();        self.imageView.image = newImage;


0 0
原创粉丝点击