Shahnawaz
Shahnawaz

Reputation: 646

iOS Help: How to use camera to take picture and save it on iPhone?

I am new to iPhone development. I need to make an App where the user can take a picture and then its saved on the iPhone and also I have to use SQLite Database to store the image and later display it.

Can anyone help me with sample code and explanation of the procedure?

EDIT: I made a button that uses an UIImageView to take picture, but I'm not sure if it works because I don't have an iPhone:

if ([UIImagePickerController isSourceTypeAvailable:
     UIImagePickerControllerSourceTypeCamera])
{
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.delegate = self;
    imagePicker.sourceType = 
    UIImagePickerControllerSourceTypeCamera;
    imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage,nil];
    imagePicker.allowsEditing = NO;
    [self presentModalViewController:imagePicker animated:YES];
    imagePicker = nil;
    newMedia = YES;
}

The above code uses the front camera

Upvotes: 1

Views: 20712

Answers (2)

Rahul Patel
Rahul Patel

Reputation: 5886

you can use UIImagePickerController class for take a picture.. you can use following methods for capture image and store it..

UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    //put code for store image
 }                

Upvotes: 11

The iOSDev
The iOSDev

Reputation: 5267

You can use the examples available on apple's developer library

see these examples

and many more reference material is available too.

Happy Coding :)

Upvotes: 4

Related Questions