IOS图像捕获并保存到UIImageView

时间:2013-12-10 18:36:07

标签: iphone ios7 uiimagepickercontroller

我正在尝试捕获图像并将其保存在imageview中。以下是代码。

- (void)imagePickerController:(UIImagePickerController *)picker
        didFinishPickingImage:(UIImage *)image
                  editingInfo:(NSDictionary *)editingInfo
{
    NSLog(@"Hello");
    [picker dismissModalViewControllerAnimated:YES];
    [_Image setImage:image];
}

- (IBAction)Capture:(UIButton *)sender {
        UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
        cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
        [self presentViewController: cameraUI animated: YES completion:nil];
}

问题是imagepickercontroller根本没有被调用!!我的.h声明是

@interface AikyaViewController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate>

我可以让相机拍摄图像,但图像不会保存在我的图像视图中。事实上,它并没有进入该功能,因为它不是NSlogging。

我是否必须链接故事板中的任何内容或任何代表初始化我错过了? Plz指导相同。

1 个答案:

答案 0 :(得分:2)

imagePickerController:didFinishPickingImage:editingInfo:已弃用

使用以下方法更改该方法:

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

 NSLog(@"done");

 [picker dismissViewControllerAnimated:YES completion:Nil];

 [image setImage:[info objectForKey:@"UIImagePickerControllerEditedImage"]];

}

并尝试更改:

- (IBAction)Capture:(UIButton *)sender {
    UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];

    [cameraUI setDelegate:self];

    [cameraUI setAllowsEditing:YES];

    cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
    [self presentViewController: cameraUI animated: YES completion:nil];
  }