我想在iOS开发中同时使用前置和后置摄像头:当我使用后置摄像头拍摄一张照片时,之后可以打开前置摄像头并拍摄另一张照片。顺便说一下,这两个照片在一张照片中:垂直排列。
以前是否有人这样做过?
答案 0 :(得分:0)
使用UIImagePickerController
拍摄照片,并使用cameraDevice property确定正在使用的相机。
为了合并图像,我通过搜索找到了一个例子(将来推荐它)merges multiple images into one image
答案 1 :(得分:0)
超级简单,这是一种简单的方法。只需用你的图像替换我的imagNamed,选择器就是创建的新方法。这通过删除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;
}