绘图 图片水印

来源:互联网 发布:excel清洗数据 编辑:程序博客网 时间:2024/05/08 19:13


新建 UIImageView *imageView    

    UIImage *oldImage = [UIImageimageNamed:@"img"];

//    开启上下文

    /**

     *  @param size#>   <#size#> description#>新图片的大小

     *  @param opaque#> <#opaque#> description#> YES不透明 NO透明

     *  @param scale#>  <#scale#> description#>

     */

    UIGraphicsBeginImageContextWithOptions(oldImage.size,NO, 0.0);

    [oldImage drawAtPoint:CGPointZero];

    

    NSString *textString =@"水印哈哈";

    

    NSDictionary *dict =@{NSFontAttributeName: [UIFontsystemFontOfSize:16.0],

                           NSForegroundColorAttributeName:[UIColorredColor]};

    [textString drawAtPoint:CGPointMake(120,170) withAttributes:dict];

//    获取新的图片

    UIImage *newImage =UIGraphicsGetImageFromCurrentImageContext();

    

//    关闭上下文

    UIGraphicsEndPDFContext();

    

    _imageView.image = newImage;

    

//    NSData *data = UIImageJPEGRepresentation(newImage, 0.003);

//    

//    UIImage *image = [UIImage imageWithData:data];

//    _imageView.image = image;

//    把图片转换成png格式的二进制文件

    NSData *data =UIImagePNGRepresentation(newImage);

////写入保存生成新的图片

    [data writeToFile:@"/Users/apple/Desktop/newImage.png" atomically:YES];

0 0