实现在图片上加一个水印 并存在document的路径下 同时在手机相册中也存一份
//首先开启imageContext找到图片
UIGraphicsBeginImageContext(self.imageView.frame.size); //找到图片 UIImage *img = [UIImage imageNamed:@"0.png"]; //画图片的位置 [img drawInRect:self.imageView.bounds]; //设置水印文字 NSString *str = @"hi"; [str drawAtPoint:CGPointMake(100, 100) withAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:30],NSForegroundColorAttributeName:[UIColor blackColor],}]; //从当前的图形的上下文获得图片 self.image = UIGraphicsGetImageFromCurrentImageContext(); //结束imageContext UIGraphicsEndImageContext();
[self.imageView setImage:self.image];
//将画的图片存到document目录中////////////// //获得document的路径 NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject]; NSLog(@"%@",documentPath); //在document中设置文件的名字 NSString *fileName = [documentPath stringByAppendingPathComponent:@"my.png"]; //创建data 暂存图片 NSData *imageData =UIImagePNGRepresentation(self.image); [imageData writeToFile:fileName atomically:YES]; //将图片存在手机的相册中中//////////////// UIImageWriteToSavedPhotosAlbum(self.image, nil, nil, nil);