从相机和图书馆拍摄照片

时间:2013-05-24 09:56:38

标签: uiimage uiimagepickercontroller

嗨,在我的应用程序中,我可以拍照或从库中选择一张照片并在imageview中显示

但我的问题是如何添加第二个图像视图并在其中显示图像

这是我的代码

- (IBAction)TakePhoto:(id)sender {
picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
[picker setSourceType:UIImagePickerControllerSourceTypeCamera];
[self presentViewController:picker animated:YES completion:NULL];
}

- (IBAction)ChoosePhoto:(id)sender {    
picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
[picker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:picker animated:YES completion:NULL];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    image = [info objectForKey:UIImagePickerControllerOriginalImage];
    [ImageView setImage:image];    // "myImageView" name of any UImageView.
    [self dismissViewControllerAnimated:YES completion:NULL];
}

-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[self dismissViewControllerAnimated:YES completion:NULL];
}

1 个答案:

答案 0 :(得分:0)

我认为你的问题是你要逐一选择两张图片。

来自相机或照片库。

试试这个:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    image = [info objectForKey:UIImagePickerControllerOriginalImage];


    if(ImageView.image == Nil)
    {
        [ImageView setImage:image];
    }
    else if(ImageView2.image == Nil)
    {
        [ImageView2 setImage:image];
    }

    [self dismissViewControllerAnimated:YES completion:NULL];
}