1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. //开启上下文 //size新的图片大小 //opaque: YES 不透明 NO 透明 UIImage *oldImage=[UIImage imageNamed:@"img"]; UIGraphicsBeginImageContextWithOptions(oldImage.size, NO, 0.0); [oldImage drawAtPoint:CGPointZero]; NSString *text=@"图片水印!"; NSDictionary *dict=@{ NSFontAttributeName:[UIFont systemFontOfSize:15], NSForegroundColorAttributeName:[UIColor redColor] }; [text drawAtPoint:CGPointMake(10, 10) withAttributes:dict]; //获取新的图片 UIImage *newImage=UIGraphicsGetImageFromCurrentImageContext(); //关闭上下文 UIGraphicsEndImageContext(); _imageView.image=newImage; //保存图片到桌面 //把图片转换成png格式的二进制 NSData *data = UIImagePNGRepresentation(newImage); [data writeToFile:@"/Users/zxc/Desktop/newImage.png" atomically:YES]; }
|