绘图
使用颜色绘制一张图片
UIGraphicsBeginImageContextWithOptions(CGSizeMake(50,50),YES,0); // 创建一个bitmap上下文
CGContextRef context =UIGraphicsGetCurrentContext(); //获取bitmap上下文
[[UIColorcolorWithRed:250/255.0green:250/255.0blue:250/255.0alpha:1]set];
CGContextFillRect(context,CGRectMake(0,0,50,50)); //绘图
UIImage *image =UIGraphicsGetImageFromCurrentImageContext();//拿到图片
UIGraphicsEndImageContext(); // 关闭上下文
// 保存图片
NSData *data =UIImageJPEGRepresentation(image,1);
[data writeToFile:@""atomically:YES];
使用图片绘制图片
UIImage *image = [UIImageimageNamed:@"2.jpg"];
UIGraphicsBeginImageContextWithOptions(image.size,YES,0);
[image drawAtPoint:CGPointMake(0,0)];
UIImage *image1 = [UIImageimageNamed:@"vip_ic_reason_1"];
[image1 drawAtPoint:CGPointMake(200,200)];
NSString *str =@"我是超人";
[str drawAtPoint:CGPointMake(120,120)withAttributes:@{NSFontAttributeName:[UIFontsystemFontOfSize:14]}];
UIImage *image11 =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *data =UIImageJPEGRepresentation(image11,1);
[data writeToFile:@"/Users/zhoupengju/Desktop/test@.png"atomically:YES];