标签:
#import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; UIImage *image = [self waterMaskImage]; UIImageView *iv = [[UIImageView alloc]initWithImage:image]; [self.view addSubview:iv]; } -(UIImage *) waterMaskImage{ CGSize imageSize = CGSizeMake(320, 200); //1. 建立图像的上下文,需要指定新生成的图像大小 UIGraphicsBeginImageContext(imageSize); //2. 绘制内容 UIImage *image = [UIImage imageNamed:@"1.png"]; [image drawInRect:CGRectMake(0, 0, imageSize.width, imageSize.height)]; //3.添加水印文字 NSString *str = @"我的水印"; [[UIColor blueColor]set] ; [str drawInRect:CGRectMake(0, imageSize.height-30, imageSize.width-20, imageSize.height) withFont:[UIFont systemFontOfSize:16] lineBreakMode:(NSLineBreakByTruncatingTail) alignment:(NSTextAlignmentRight)]; //4.获取到新生成的图像,从当前上下文获取到新绘制的图像 UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return newImage; } @end
标签:
原文地址:http://www.cnblogs.com/wlxm/p/4295419.html