iOS开发之保存图片到手机相册
2014-11-04 16:15
477 查看
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(60, 100, 200, 300)];
_imageView.image = [UIImage imageNamed:@"hmt.jpg"];
_imageView.userInteractionEnabled = YES;
[self.view addSubview:_imageView];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] init];
tapGesture.numberOfTapsRequired = 1;
tapGesture.numberOfTouchesRequired = 1;
[tapGesture addTarget:self action:@selector(tapSaveImageToIphone)];
[self.imageView addGestureRecognizer:tapGesture];
}
- (void)tapSaveImageToIphone{
/**
* 将图片保存到iPhone本地相册
* UIImage *image 图片对象
* id completionTarget 响应方法对象
* SEL completionSelector 方法
* void *contextInfo
*/
UIImageWriteToSavedPhotosAlbum(self.imageView.image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(voidvoid *)contextInfo{
if (error == nil) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"已存入手机相册" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil nil];
[alert show];
}else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"保存失败" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil nil];
[alert show];
}
}
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(60, 100, 200, 300)];
_imageView.image = [UIImage imageNamed:@"hmt.jpg"];
_imageView.userInteractionEnabled = YES;
[self.view addSubview:_imageView];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] init];
tapGesture.numberOfTapsRequired = 1;
tapGesture.numberOfTouchesRequired = 1;
[tapGesture addTarget:self action:@selector(tapSaveImageToIphone)];
[self.imageView addGestureRecognizer:tapGesture];
}
- (void)tapSaveImageToIphone{
/**
* 将图片保存到iPhone本地相册
* UIImage *image 图片对象
* id completionTarget 响应方法对象
* SEL completionSelector 方法
* void *contextInfo
*/
UIImageWriteToSavedPhotosAlbum(self.imageView.image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(voidvoid *)contextInfo{
if (error == nil) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"已存入手机相册" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil nil];
[alert show];
}else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"保存失败" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil nil];
[alert show];
}
}
相关文章推荐
- iOS开发之保存图片到手机相册
- iOS之保存图片到手机相册中
- iOS开发——打开手机相册,获取图片
- iOS 开发批量保存图片到相册时丢图片的解决方法
- iOS开发笔记之保存图片到相册
- iOS开发技巧之:相册中的GIF图片的读取与保存
- iOS 图片保存手机相册
- IOS开发——保存图片到相册
- Android开发——相册拍照_03.解决相机拍照之后部分手机无法将图片保存到路径或部分手机点击相机确定无法返回问题
- IOS开发从手机相册中上传头像到APP的个人中心同时保存到数据库
- iOS开发 长按图片保存到相册
- iOS开发小技巧--实现将图片保存到本地相册
- 关于iOS开发中长按保存图片到相册
- iOS开发-OC之图片保存到相册
- iOS开发 系统自带保存图片到相册的方法
- IOS开发之——保存图片到相册的功能实现
- iOS开发 - 保存图片到相册和保存屏幕截图到相册
- iOS 开发批量保存图片到相册时丢图片的解决方法
- iOS 开发: 自定义相册, 保存多张图片到自定义相册中
- 安卓开发下载图片保存到手机后图片没在相册看到的问题