//创建一个UIImage对象
UIImage *image = [UIImageimageNamed:@"scene1.jpg"];
//1.建立bitmap Context
UIGraphicsBeginImageContext(image.size);
//2.把原图绘制到context上
[imagedrawInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
//3.把水印文字绘制到context上。
//在左下角加水印
CGRect textFrame =CGRectMake(0, image.size.height-40, 200, 40);
//设置水印文字属性
UIFont *font = [UIFontboldSystemFontOfSize:30];
NSMutableParagraphStyle*style = [[NSMutableParagraphStyle alloc] init];
style.alignment = NSTextAlignmentCenter;
UIColor *color = [UIColorcolorWithRed:254.0/255 green:201.0/255 blue:21.0/255 alpha:1];
[text drawInRect:textFramewithAttributes: @{NSFontAttributeName:font, NSForegroundColorAttributeName:color,NSParagraphStyleAttributeName:style}];
//4.从bitmap context上获取加了水印以后的图片。
UIImage *waterImage =UIGraphicsGetImageFromCurrentImageContext();
//5.关闭bitmap context。
UIGraphicsEndImageContext();
//6.返回获取的图片
return waterImage;
此方法最好独立成一个单独的类,只需一类方法就能完成。