1 //1.加载要添加水印图片 2 UIImage * image = [UIImage imageNamed:@"img05"]; 3 4 //2.开启和图片大小相同的图形上下文(bitmap) 5 UIGraphicsBeginImageContextWithOptions(image.size, NO, 0.0); 6 7 8 //3.把图片绘制到刚刚开启的图形上下文中 9 [image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)]; 10 11 12 //4.添加文字水印 13 NSString * text = @"美人你一直是我的春天,你是我的世外桃源"; 14 15 NSDictionary * attrs = @{NSForegroundColorAttributeName:[UIColor redColor], 16 NSFontAttributeName:[UIFont systemFontOfSize:20.f] 17 }; 18 [text drawInRect:CGRectMake(200, 500, 300, 200) withAttributes:attrs]; 19 20 21 22 //4.1 添加图片水印 23 //加载水印图片 24 UIImage * logoImage = [UIImage imageNamed:@"logo"]; 25 26 [logoImage drawInRect:CGRectMake(300, 700, 101, 38)]; 27 28 //5.从图形上下文中获取图片 29 UIImage * getImage = UIGraphicsGetImageFromCurrentImageContext(); 30 31 //5.1 结束上下文 32 UIGraphicsEndImageContext(); 33 34 //6.保存图片到相册 35 UIImageWriteToSavedPhotosAlbum(getImage, nil, nil, nil);
浙公网安备 33010602011771号