});
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
if (error) {
[MBProgressHUD showError:@"保存失败,请检查是否拥有相关的权限"];
}else
{
// [MBProgressHUD showMessage:@"保存成功!"];
[MBProgressHUD showSuccess:@"保存成功!"];
}
}
@end
把截取的图片保存到手机的相册中:
说明:把整个屏幕画到一张图片里
1.创建一个bitmap的上下文
2.将屏幕绘制带上下文中
3.从上下文中取出绘制好的图片
4.保存图片到相册
补充:把图片写入到文件的代码
//3.从上下文中取出绘制好的图片
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
NSData *data = UIImagePNGRepresentation(newImage);
NSString *path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"abc.png"];
NSLog(@"%@", path);
[data writeToFile:path atomically:YES];
三、补充
保存成功和保存失败之后应该做些事情?
系统推荐的方法:
复制代码
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
if (error) {
[MBProgressHUD showError:@"保存失败,请检查是否拥有相关的权限"];
}else
{
// [MBProgressHUD showMessage:@"保存成功!"];
[MBProgressHUD showSuccess:@"保存成功!"];











