码迷,mamicode.com
首页 > 其他好文 > 详细

绘图quartz之加水印

时间:2015-10-11 00:22:55      阅读:275      评论:0      收藏:0      [点我收藏+]

标签:

 
实现在图片上加一个水印  并存在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);
 

绘图quartz之加水印

标签:

原文地址:http://www.cnblogs.com/lishanshan/p/4868600.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!