iOS 圖片上新增水印

weixin_33749242發表於2016-12-04
- (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;
}

相關文章