将图片保存到相册(本地)
来源:互联网 发布:pla pocket算法 编辑:程序博客网 时间:2024/05/17 07:29
方法比较简单:
//保存到相册 UIImageWriteToSavedPhotosAlbum(_fullImageView.image, self, @selector(imageSavedToPhotosAlbum:didFinishSavingWithError:contextInfo:), nil);
//保存后调用的方法:
- (void)imageSavedToPhotosAlbum:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{ NSString *message = @"呵呵哒"; if (!error) { message = @"成功保存到相册"; }else { message = [error description]; } NSLog(@"message is %@",message);}
以上两段代码就可以保存到图片到本地。一般都是长按保存图片,添加长按手势:
//添加长按手势到_scrollview UILongPressGestureRecognizer *press = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(zAction)];//这里我是添加到滑动视图上了,滑动视图上有一个imageView
<p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; font-family: Menlo;">//设置长按最短时间</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; font-family: Menlo; color: rgb(112, 61, 170);"><span style="font-variant-ligatures: no-common-ligatures; color: #000000"></span><pre name="code" class="objc"><span style="font-family: Arial, Helvetica, sans-serif; font-size: 12px;"></span><pre name="code" class="objc">press.minimumPressDuration = 1;
[_scrollview addGestureRecognizer:press];
长按后调用的方法
//长按图片调用的方法。- (void)zAction{ UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"是否保存图片到本地" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil]; [alertView show]; }
//提示框调用的代理方法:
//提示框的代理方法- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ if (buttonIndex == 1) { //保存到相册 UIImageWriteToSavedPhotosAlbum(_fullImageView.image, self, @selector(imageSavedToPhotosAlbum:didFinishSavingWithError:contextInfo:), nil); //获得沙盒路径 ------ 保存到沙盒// NSString *path = NSHomeDirectory();// // //设置图片保存的路径// NSString *imagePath = [path stringByAppendingString:@"/Documents"];// //将图片写入本地// [UIImagePNGRepresentation(_fullImageView.image) writeToFile:imagePath atomically:YES];// }}
//保存到相册成功后调用的方法- (void)imageSavedToPhotosAlbum:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{ NSString *message = @"呵呵哒"; if (!error) { message = @"成功保存到相册"; }else { message = [error description]; } NSLog(@"message is %@",message);}
0 0
- 将图片保存到相册(本地)
- 将图片保存到本地相册
- 图片保存到本地相册
- 保存图片到本地相册
- 保存图片到本地相册
- 保存图片到本地相册
- 保存图片到本地相册
- 保存图片到本地相册
- 将ImageView中的图片保存到本地相册
- 将相机/相册的图片保存到本地沙盒
- iOS 将图片保存到iPhone本地相册
- 将图片保存到相册
- 将图片保存到相册
- 将图片保存到相册
- 将图片保存在本地相册中
- 将突破保存到本地相册
- ios--保存图片到本地相册
- IOS图片保存到本地相册
- C++片段
- STL之set实现
- 软件测试需求
- activity生命周期---starting an activity 特别好 强烈推荐(http://blog.sina.com.cn/s/blog_8191005601019pp5.html)
- 全局最小割Stoer-Wagner算法 时间复杂度(o^3)
- 将图片保存到相册(本地)
- C++ 最简单的string与wstring互相转换
- Bootstrap 初步
- 解决更新 Xcode 之后, 插件失效问题
- SQL SELECT INTO 语句 高级教程
- Qt 连接MySQL数据库
- Displaying Bitmaps Efficiently (二)-----Processing Bitmaps Off the UI Thread
- SQL CREATE DATABASE 语句 高级教程
- *LeetCode-Unique Word Abbreviation