iOS 图片上添加水印

- (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;
}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容