iOS 开发每天分享优质文章

iOS 图片上添加水印

2016-12-04  本文已影响541人  孟豊Mike
- (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;
}

上一篇 下一篇

猜你喜欢

热点阅读