1

I'd like to use the front and back camera at the same time in iOS developing:when I take one photo using back camera,after that the front camera could be opened and take another photo.By the way,this two photos are in the one picture:Vertical arrangement.

Is anybody has done this before?

voisvous
  • 163
  • 1
  • 1
  • 8
  • I think you mean open front/back camera sequentially, because your description doesn't imply that the pictures are taken simultaneously, and is not possible with the current API as I understand it. However, using a `UIImagePickerController` to take a front and rear camera shot back to back is perfectly possible with the current API. – gudatcomputers Jul 28 '14 at 03:00
  • Yeah,I mean using back camera take one photo first,then using front camera take another one.And the photos on one picture at last. – voisvous Jul 28 '14 at 03:22

2 Answers2

0

Use UIImagePickerController to take the pictures, and use the cameraDevice property to determine which camera is in use.

For merging images I found an example via searching(recommend it in the future) merges multiple images into one image

Community
  • 1
  • 1
gudatcomputers
  • 2,822
  • 2
  • 20
  • 27
0

Super simple this is the an easy way of doing it. Just replace my imagNamed with you images and the selector is the new methods that were created. This is used for a custom camera by removing showsCameraControls = NO;

@interface yourClassName () {
   UIImagePickerController *picker; //this calls the video/photo screen
   UIButton *cameraFront, *cameraBack //front and back buttons
}

//in your UIImagePickerController
picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
picker.showsCameraControls = NO;

[cameraFront setBackgroundImage:[UIImage imageNamed:@"camera_switch_logo"] forState:UIControlStateNormal];
UITapGestureRecognizer *camerafront = [[UITapGestureRecognizer alloc]
                                           initWithTarget:self action:@selector(deviceModeFront:)];
[cameraFront addGestureRecognizer:camerafront];

[cameraBack setBackgroundImage:[UIImage imageNamed:@"camera_switch_logo2"] forState:UIControlStateNormal];
UITapGestureRecognizer *cameraback = [[UITapGestureRecognizer alloc]
                                          initWithTarget:self action:@selector(deviceModeBack:)];
[cameraBack addGestureRecognizer:cameraback];
cameraBack.hidden = true;

//These are the new methods created as the selector for when image is pressed
- (IBAction)deviceModeFront:(id)sender {
    [picker setCameraDevice:UIImagePickerControllerCameraDeviceFront];
    cameraFront.hidden = true;
    cameraBack.hidden = false;
}

- (IBAction)deviceModeBack:(id)sender {
    [picker setCameraDevice:UIImagePickerControllerCameraDeviceRear];
    cameraFront.hidden = false;
    cameraBack.hidden = true;
}