博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
访问系统相册
阅读量:4078 次
发布时间:2019-05-25

本文共 1767 字,大约阅读时间需要 5 分钟。

1:首先遵守协议

UIImagePickerControllerDelegate,UINavigationControllerDelegate

2:

- (void)imageChange:(UIButton *)button{

    NSLog(@"调用系统相册");

   if (button!=self.button) {

       self.isChange=NO;

       self.button=button;

    }

    self.isChange=YES;

    UIImagePickerController *imagePickerController = [[UIImagePickerControlleralloc] init];

    imagePickerController.delegate =self;

    imagePickerController.allowsEditing =YES;

    imagePickerController.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;

    [selfpresentViewController:imagePickerController animated:YEScompletion:^{}];

}

#pragma mark - 保存图片至沙盒

- (void) saveImage:(UIImage *)currentImage withName:(NSString *)imageName

{

   NSData *imageData = UIImageJPEGRepresentation(currentImage, 0.5);

    NSString *fullPath = [[NSHomeDirectory()stringByAppendingPathComponent:@"Documents"]stringByAppendingPathComponent:imageName];

    [imageDatawriteToFile:fullPath atomically:NO];

}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{

    [picker dismissViewControllerAnimated:YEScompletion:^{}];

    UIImage *image = [infoobjectForKey:UIImagePickerControllerOriginalImage];

    [selfsaveImage:imagewithName:@"currentImage.png"];

    NSString *fullPath = [[NSHomeDirectory()stringByAppendingPathComponent:@"Documents"]stringByAppendingPathComponent:@"currentImage.png"];

   if (self.isChange==YES) {

       self.savedImage = [[UIImagealloc] initWithContentsOfFile:fullPath];

        self.addImageView=[[UIImageViewalloc]initWithFrame:CGRectMake(0,0,88,87)];

        self.addImageView.layer.masksToBounds=YES;

        self.addImageView.layer.cornerRadius=44;

        self.addImageView.image=self.savedImage;

        [self.buttonaddSubview:self.addImageView];

    }elseif (self.isChange==NO){

       return ;

    }

}

原文链接:http://blog.csdn.net/darongzi1314/article/details/43405327

你可能感兴趣的文章
斯坦福大学机器学习——因子分析(Factor analysis)
查看>>
linux对于没有写权限的文件如何保存退出vim
查看>>
IntelliJ IDEA 下的svn配置及使用的非常详细的图文总结
查看>>
【IntelliJ IDEA】idea导入项目只显示项目中的文件,不显示项目结构
查看>>
ssh 如何方便的切换到其他节点??
查看>>
JSP中文乱码总结
查看>>
Java实现DES加密解密
查看>>
HTML基础
查看>>
Java IO
查看>>
Java NIO
查看>>
Java大数据:Hbase分布式存储入门
查看>>
大数据学习:Spark RDD操作入门
查看>>
大数据框架:Spark 生态实时流计算
查看>>
大数据入门:Hive和Hbase区别对比
查看>>
大数据入门:ZooKeeper工作原理
查看>>
大数据入门:Zookeeper结构体系
查看>>
大数据入门:Spark RDD基础概念
查看>>
大数据入门:SparkCore开发调优原则
查看>>
大数据入门:Java和Scala编程对比
查看>>
大数据入门:Scala函数式编程
查看>>