Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use camera inside my App controller

How can I open camera inside my app controller.

I don't want to present built in camera controller.
I want to make my own camera sort of app.

Any suggestion or guide will be highly appreciated.

like image 252
Ahad Khan Avatar asked May 11 '14 09:05

Ahad Khan


1 Answers

You can easily use UIImagePickerController for this

  1. Declare UIImagePickerController *imagePickerController; globally for the class
  2. Declare protocols
    • @interface YourClassName : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate>

imagePickerController = [[UIImagePickerController alloc] init];
[imagePickerController setDelegate:self];
[imagePickerController setSourceType:UIImagePickerControllerSourceTypeCamera];
[imagePickerController setMediaTypes:@"public.image"]]; //specify image (not video)
[imagePickerController setShowsCameraControls:NO]; //hide default camera controls
[imagePickerController setNavigationBarHidden:YES];
[imagePickerController setToolbarHidden:YES];
[imagePickerController setAllowsEditing:NO];
[self.view addSubview:imagePickerController.view];

Use the takePicture method for the UIImagePickerController object like and assign it on a button action, like:

-(IBAction)btnTakePictureAct:(UIButton *)sender
{
    [imagePickerController takePicture];
}

Use the delegate -imagePickerController:didFinishPickingMediaWithInfo: to get the image.

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

See this, get an idea, make your custom camera controls.
Refer: UIImagePickerController Apple Doc

like image 65
staticVoidMan Avatar answered Oct 24 '22 06:10

staticVoidMan