Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating A Preview Screen With A Custom Camera

I'm creating an app where I made a custom overlay for the camera. I noticed that when I used the normal defaults for the camera, a preview comes up where you have the option to retake the photo or to use it. Is there an easy way to show that screen when working with custom overlays? Thanks!

like image 430
A.J. S. Avatar asked Feb 14 '26 04:02

A.J. S.


1 Answers

Yes..... for this you have to create one camera overlay view programmatically .

And then write this code...

   //set our custom overlay view

    imagePickerController.cameraOverlayView = overlayView;
    imagePickerController.showsCameraControls = NO;

To show a overlay view on the camera screen , use above code. For adding overlay view no need to use addSubView method.

When you will use the normal camera, then by default cancel button, use, Ratake and camera reverse button comes on your screen. And if you will make showsCameraControls "NO". then these button won't come. Then programmatically you have to add UIButton on camera overlay View and set their functionality.

Here i am adding one button on Camera overlay view.

     //add Camera Reverse button to the overlay view.

    UIButton *btnCamReverse = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [btnCamReverse setBackgroundImage:[UIImage imageNamed:@"image.png"]   
                                                 forState:UIControlStateNormal];

    //set the frame
    CGRect btnCamReverseFrame = CGRectMake(400, 250, 50, 50);
    btnCamReverse.frame = btnCamReverseFrame;

    [btnCamReverse addTarget:self
                  action:@selector(onClickButtonCamReverse:)
        forControlEvents:UIControlEventTouchUpInside];

    [overlayView addSubview:btnCamReverse];



    //IBAction (for switching between front and rear camera).

    -(IBAction)onClickButtonCamReverse:(id)sender
    {
      if(imagePickerController.cameraDevice == UIImagePickerControllerCameraDeviceFront)
        {
          imagePickerController.cameraDevice = UIImagePickerControllerCameraDeviceRear;
        }
      else 
        {
          imagePickerController.cameraDevice = UIImagePickerControllerCameraDeviceFront;
        }
    }

For camera overlay example open the below link.....

https://github.com/anka/bw_examples

Camera with Custom View

It worked for me... I hope it works for you as well.

like image 56
Anand Gautam Avatar answered Feb 15 '26 19:02

Anand Gautam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!