我如何参考我刚刚在iOS上拍摄的图片?

时间:2014-04-15 03:43:52

标签: ios objective-c uiimagepickercontroller

我正在编写一个应用程序,允许用户拍照,然后在图像视图中显示。

我知道我需要编写一系列类似于以下内容的代码:_imageView.image = picker.image;,但我不确定我需要替代picker.image。这就是我现在所拥有的,它给了我一个错误。

基本上,我所问的是如何参考刚拍摄的照片?服用后,这张照片在哪里(在记忆中?)?我怎样才能在以后引用它(比如显示和保存那些东西)?

我已经阅读了官方的Apple文档并查看了一些教程,但答案似乎并未出现在其中。正如我之前的帖子中提到的,我在解析Apple文档时遇到了很多麻烦,所以对我来说它几乎没用。

谢谢!

2 个答案:

答案 0 :(得分:1)

我使用以下委托方法来获取用户从照片选择器视图中选择的任何照片

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [picker dismissViewControllerAnimated:false completion:nil];
    image = [info objectForKey:@"UIImagePickerControllerOriginalImage"]; 

}

答案 1 :(得分:0)

在点按相机按钮时调用cameraTapped方法

-(IBAction)cameraTapped:(id)sender 
{
    UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
    if ([UIImagePickerController  isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
        [imagePickerController setSourceType:UIImagePickerControllerSourceTypeCamera];
    else
        [imagePickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
    [imagePickerController setDelegate:self];
    [self presentViewController:imagePickerController animated:YES completion:nil];
}


-(void)imagePickerController:(UIImagePickerController *)picker      didFinishPickingMediaWithInfo:(NSDictionary *)info
{
     // photo
     _imageView.image = info[UIImagePickerControllerOriginalImage]];

    [self dismissViewControllerAnimated:YES completion:nil];
}