好好学习天天 2019-11-01
#pragma mark 先获取本地图片或者网络图片
- (void)saveHeaderImageWith:(NSString *)path
{
UIImage *img = [UIImage imageWithContentsOfFile:path];
//这里img也可以是从网络获取的图片
[self saveImageToPhotos:img];
}
#pragma mark 保存图片
- (void)saveImageToPhotos:(UIImage*)savedImage
{
UIImageWriteToSavedPhotosAlbum(savedImage, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
}
#pragma mark 系统的完成保存图片的方法
- (void)image: (UIImage *) image didFinishSavingWithError: (NSError *) error contextInfo: (void *) contextInfo
{
NSString *msg = nil ;
if (error != NULL) {
msg = @"保存图片失败" ;
} else {
msg = @"保存图片成功" ;
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"保存图片结果提示" message:msg delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
[alert show];
}