Marcelo Roque
Marcelo Roque

Reputation:

iPhone 3.1 SDK Camera Access

How can I create an application that would initiate a camera and update the image view with the image picked by the camera?

Upvotes: 5

Views: 6834

Answers (2)

Vaishnavi Naidu
Vaishnavi Naidu

Reputation: 2627

Try this out.

In the viewDidLoad method, initialize the UIImagePickerController, assign its property sourceType as UIImagePickerControllerSourceTypeCamera and delegate as self.

Define a button in your view controller where on its click event get the modal view of the imagepicker, like:

[self presentModalViewController:self.picker animated:YES];

here picker is the object of UIImagePickerController.

Next,implement the didFinishPickingMediaWithInfo delegate of UIImagePickerController. In this delegate, you can assign a UIImage to the Dictionary object info, then save the image to your local instance of UIImageView(its ImageToSave below)

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

[[picker parentViewController] dismissModalViewControllerAnimated:YES];
UIImage *img = [info objectForKey:@"UIImagePickerControllerImage"];
ImageToSave.image = img;

}

Do not forget to include the UIImagePickerControllerDelegate into your main view controller's .h file.

See if this works or not.

Upvotes: 1

If you think about it, self.view = picker.cameraOverlayView just copies an empty transparent view over you own!! It doesn't even add it to the screen, not that it would work...

Instead, you need to present the picker controller:

[self.navigationController presentModalViewController:picker animated:YES];

Then make sure to implement the delegate calls (which it looks like you may have since you already set the delegate)

Upvotes: 0

Related Questions