iphone sdk如何从相机拍照并在同一视图中显示图像?

Uni*_*ver -5 iphone objective-c uiimagepickercontroller ios4

我将创建一个按钮和imageview.我将创建IBAction按钮打开UIImagepicker拍照.我需要之后图像需要在imageview中显示.如何得到这个.任何人都可以帮助我.

roh*_*tel 5

IBAction单击按钮调用此方法.它将打开UIImagePickerController以从相机捕获图像.

-(IBAction)openCamera
{
    @try 
    {
        UIImagePickerController *picker = [[UIImagePickerController alloc] init];  
        picker.sourceType = UIImagePickerControllerSourceTypeCamera;  
        picker.delegate = self; 

        [self presentModalViewController:picker animated:YES];
        [picker release];
    }
    @catch (NSException *exception) 
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Camera" message:@"Camera is not available  " delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
}
Run Code Online (Sandbox Code Playgroud)

完成拍摄图像后,将调用此委托.将图像存储在您的UIImageView.

-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info
{
    [picker dismissModalViewControllerAnimated:YES];
    self.imageView.image=[info objectForKey:@"UIImagePickerControllerOriginalImage"];
}
Run Code Online (Sandbox Code Playgroud)