码迷,mamicode.com
首页 > 移动开发 > 详细

iOS访问手机自带的相册

时间:2015-02-02 10:50:34      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:ios   相册   

1:首先遵守协议

UIImagePickerControllerDelegate,UINavigationControllerDelegate

2:

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

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

    if (button!=self.button) {

        self.isChange=NO;

        self.button=button;

    }

    self.isChange=YES;

    UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];

    imagePickerController.delegate = self;

    imagePickerController.allowsEditing = YES;

    imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

    [self presentViewController:imagePickerController animated:YES completion:^{}];

}

#pragma mark - 保存图片至沙盒

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

{

    NSData *imageData = UIImageJPEGRepresentation(currentImage, 0.5);

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

    [imageData writeToFile:fullPath atomically:NO];

}

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

    [picker dismissViewControllerAnimated:YES completion:^{}];

    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];

    [self saveImage:image withName:@"currentImage.png"];

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

    if (self.isChange==YES) {

        self.savedImage = [[UIImage alloc] initWithContentsOfFile:fullPath];

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

        self.addImageView.layer.masksToBounds=YES;

        self.addImageView.layer.cornerRadius=44;

        self.addImageView.image=self.savedImage;

        [self.button addSubview:self.addImageView];

    }else if (self.isChange==NO){

        return ;

    }

    

}


iOS访问手机自带的相册

标签:ios   相册   

原文地址:http://blog.csdn.net/darongzi1314/article/details/43405327

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!