图片水印实现

来源:互联网 发布:vscode 字体颜色 编辑:程序博客网 时间:2024/05/17 06:17

水印:在图片上加上防止他人盗图的半透明logo,文字,图标,然后生成一张新的图片

下面举一例:
UIImage *oldImage = [UIImage imageNamed:@”图片名称”];
// 开启上下文
// size 新的图片大小
// opaque YES 不透明 NO 透明
UIGraphicsBeginImageContextWithOptions(oldImage.size, NO, 0.0);
[oldImage drawAtPoint:CGPointZero];
NSString *text = @”我要高薪 !”;
NSDictionary *dict = @{
NSFontAttributeName : [UIFont systemFontOfSize:15],
NSForegroundColorAttributeName : [UIColor redColor]
};
[text drawAtPoint:CGPointMake(120, 170) withAttributes:dict];
// 获取新的图片
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
// 关闭上下文
UIGraphicsEndImageContext();
_imageView.image = newImage;
// 把图片转换成png格式的二进制数据
NSData *data = UIImagePNGRepresentation(newImage);
// 写入桌面
[data writeToFile:@”/Users/apple/Desktop/newImage.png” atomically:YES];

0 0
原创粉丝点击