iOS 图片上添加水印

作者: 孟豊Mike | 来源:发表于2016-12-04 14:34 被阅读541次
- (UIImage *)normalizedImage:(UIImage*)image withText:(NSString *)text {
    if (image.imageOrientation == UIImageOrientationUp) return image;
    UIGraphicsBeginImageContextWithOptions(image.size, NO, image.scale);
    [image drawInRect:(CGRect){0, 0, image.size}];
    //    绘制文字
    [[UIColor whiteColor] set];
    CGRect rect = CGRectMake(40, image.size.height - 40, 150, 40);
    //这里设置了字体,和倾斜度,具体其他参数
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:30],
               NSForegroundColorAttributeName:[UIColor whiteColor]};   
    [text drawInRect:rect withAttributes:dic];
    
    UIImage *normalizedImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return normalizedImage;
}

相关文章

网友评论

    本文标题:iOS 图片上添加水印

    本文链接:https://www.haomeiwen.com/subject/aoehmttx.html