zoukankan      html  css  js  c++  java
  • 绘图quartz之加水印

     
    实现在图片上加一个水印  并存在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);
     
    对上述的代码,有任何疑问,可以在下方留言。 也可以给我发邮件咨询:673658917@qq.com 或者是直接加qq:673658917 转载请注明出处,谢谢合作。 睡觉舒服,那是给死人准备的,加油吧,一年后你会感谢现在的自己的。
  • 相关阅读:
    学习进度(十一)
    学习进度(十)
    人月神话阅读笔记1
    SQL SUM() 函数
    SQL GROUP BY 语句
    SQL HAVING 子句
    SQL UCASE() 函数
    SQL LCASE() 函数
    SQL MID() 函数
    SQL LEN() 函数
  • 原文地址:https://www.cnblogs.com/lishanshan/p/4868600.html
Copyright © 2011-2022 走看看