繪圖 圖片水印


新建 UIImageView *imageView    

    UIImage *oldImage = [UIImage imageNamed:@"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: [UIFont systemFontOfSize:16.0],

                           NSForegroundColorAttributeName:[UIColor redColor]};

    [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];

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章