{
{if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *imagePickerCtrl = [[UIImagePickerController alloc] init];
imagePickerCtrl.delegate = self;
imagePickerCtrl.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:imagePickerCtrl animated:YES completion:nil];
}
else
{
[Utils alertWithMessage:@"您的设备没有相机" tilte:@"提示"];
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
//取得选取的图片
UIImage *img = [info objectForKey:UIImagePickerControllerOriginalImage];
//拍摄多张照片必不可少的一步,不信可以注释掉试试
UIImage *t= [img thumbnailImage:120 transparentBorder:0 cornerRadius:0 interpolationQuality:kCGInterpolationHigh];
NSData *data = UIImageJPEGRepresentation(t, 1);
UIImage *scaleImage = [UIImage imageWithData:data];
UIImage *newImg = [scaleImage fixOrientation];
[self.addImgArray addObject:newImg];
//保存图片到本地相册
UIImageWriteToSavedPhotosAlbum(img, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
[picker dismissViewControllerAnimated:YES completion:^{
[self.tableView reloadData];
}];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
if (error) {
[MBProgressHUD showSuccess:@"保存失败" toView:nil];
} else {
MJPhoto *photo = _photos[_currentPhotoIndex];
photo.save = YES;
_saveImageBtn.enabled = NO;
[MBProgressHUD showSuccess:@"成功保存到相册" toView:nil];
}
}