图片加水印

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //开启图片上下文,画图片
    UIImage *image = [UIImage imageNamed:@"黄人"];
    UIGraphicsBeginImageContextWithOptions(image.size, NO, 1);
    [image drawAtPoint:CGPointMake(0, 0)];
    
    //画文字
    NSString *str = @"@360百度";
    /*注意:同时设置了空心的两个属性 NSStrokeWidthAttributeName 和
      NSStrokeColorAttributeName (需两个同时设置才有效),
     文字前景色 NSForegroundColorAttributeName 就无效果了*/
    [str drawAtPoint:CGPointZero withAttributes:@{NSStrokeWidthAttributeName:@2.0, 
      NSStrokeColorAttributeName:[UIColor grayColor], 
      NSFontAttributeName:[UIFont systemFontOfSize:50]}];
    
    //导出图片
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    
    //保存到桌面
    [UIImagePNGRepresentation(newImage) writeToFile:@"/Users/mengmei/Desktop/黄人.png" atomically:YES]; 
    self.imageView.image = newImage; //显示到imageView
    
    //关闭上下文
    UIGraphicsEndImageContext();
}

效果###

黄人.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容