-(UIImage *)aspjpegImage:(UIImage *)img withWord:(NSString *)word
{
NSString* mark = word;
int w = img.size.width;
int h = img.size.height;
//UIGraphicsBeginImageContext创建一个基于位图的上下文(context),并将其设置为当前上下文(context)
UIGraphicsBeginImageContext(img.size);
[img drawInRect:CGRectMake(0, 0, w, h)];
NSDictionary *attr = @{
NSFontAttributeName: [UIFont boldSystemFontOfSize:20], //设置字体
NSForegroundColorAttributeName : [UIColor redColor] //设置字体颜色
};
//文本绘制 attr代表文本属性
[mark drawInRect:CGRectMake(0, 10, 100, 50) withAttributes:attr]; //左上角
[mark drawInRect:CGRectMake(w - 200, 10, 200, 50) withAttributes:attr]; //右上角
[mark drawInRect:CGRectMake(w - 200, h - 50 - 10, 200, 50) withAttributes:attr]; //右下角
[mark drawInRect:CGRectMake(0, h - 50 - 10, 200, 50) withAttributes:attr]; //左下角
UIImage *newImg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImg;
}
//使用
UIImage * syImage= [self aspjpegImage:image withWord:@"@哈哈同学"];