- (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;
}
网友评论