获取系统相册,并保存文件
来源:互联网 发布:java源代码怎么运行 编辑:程序博客网 时间:2024/05/18 02:45
<span style="font-size:18px;">#import "ViewController.h"@interface ViewController ()<UIActionSheetDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate>@property (weak, nonatomic) IBOutlet UIImageView *icon;@property (weak, nonatomic) IBOutlet UIImageView *imageView;@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; _icon.layer.cornerRadius = _icon.frame.size.width / 2;}- (IBAction)getPhoto:(id)sender { UIAlertController *alter = [UIAlertController alertControllerWithTitle:@"是否打开相机" message:@"打开" preferredStyle:UIAlertControllerStyleActionSheet]; //判断是否有相机 if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { UIAlertAction *alt = [UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) { //相机 UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init]; imagePickerController.delegate = self; imagePickerController.allowsEditing = YES; imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera; [self presentViewController:imagePickerController animated:YES completion:nil]; }]; [alter addAction:alt]; } //打开相册 UIAlertAction *action = [UIAlertAction actionWithTitle:@"从相册中选取" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) { UIImagePickerController *picController = [[UIImagePickerController alloc] init]; picController.delegate = self; picController.allowsEditing = YES; //跳转到相册页面 <span style="color:#FF0000;"> picController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; [self presentViewController:picController animated:YES completion:nil];</span> }]; UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]; [alter addAction:action]; [alter addAction:cancel]; [self presentViewController:alter animated:YES completion:nil];}//保存到沙盒文件- (void)savePhoto:(UIImage *)image withName:(NSString *)name{ NSData *data = UIImageJPEGRepresentation(image, 1); //获取沙盒目录 NSString *path = [[NSHomeDirectory() stringByAppendingString:@"Documents"]stringByAppendingString:name]; NSLog(@"%@", path); [data writeToFile:path atomically:YES]; }//选中图片以后的代理方法- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{ [picker dismissViewControllerAnimated:YES completion:nil]; UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage]; //保存到沙盒 [self savePhoto:image withName:@"保存的图片.jpg"]; NSString *path = [[NSHomeDirectory() stringByAppendingString:@"Documents"] stringByAppendingString:@"保存的图片.jpg"]; UIImage *saveImage = [[UIImage alloc] initWithContentsOfFile:path]; [_icon setImage:saveImage]; [_imageView setImage:saveImage];}//选择取消后的代理方法- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{ [self dismissViewControllerAnimated:YES completion:nil];}</span>
0 0
- 获取系统相册,并保存文件
- 获取文件的系统图标并保存
- 保存图片到系统相册并更新
- 获取系统相册并裁剪图片
- 调用系统相机和系统相册,并保存到沙盒中
- iOS 把图片保存到相册,并获取图片文件名
- 保存照片到系统相册并打开查看
- 保存图片到本地,并及时在系统相册更新
- IOS view截图并保存到系统相册
- IOS view截图并保存到系统相册
- android新版本的拍照并保存系统相册功能
- 通过系统相册来获取文件绝对路径
- iOS 系统相册获取图片,保存图片,以及剪切图片
- 关于获取imageview上的图片,保存到相册并通知相册自动更新
- 从网络获取图片并保存到手机相册,保存成功但是相册不显示图片问题
- 获取屏幕截图 并保存到相册 弹出提示框 提示图片保存成功
- 截图并保存到相册
- 【Android】系统相机、相册获取照片并显示
- vsftpd配置文件详解
- windows和ubuntu下乱码问题
- 慕课网AngularJS实战课程笔记
- UITableView的常用代理方法
- EclEmma 代码覆盖测试工具分析
- 获取系统相册,并保存文件
- POJ 3311 Hie with the Pie
- 第六周实践项目2————设计武器类
- Linux C线程同步
- 我所理解的OOP——UML六种关系
- Servlet的生命周期
- Guava - EventBus(事件总线)
- JavaScript/JQuery] AJAX机制详解以及跨域通信
- 冒泡排序PHP实现