我需要使用前置攝像頭並在iPhone中打開背光LED。 我該怎麼做? 我可以使用此代碼打開前置攝像頭:在iPhone上同時打開閃光燈和前置攝像頭
- (void) turnCameraOn {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
imagePicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
imagePicker.showsCameraControls = YES;
[self presentViewController:imagePicker animated:YES completion:nil];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Camera unavaliable"
message:@"Unable to find camera on your device."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil, nil];
[alert show];
alert = nil;
}
}
,我可以打開LED與此代碼
- (void) turnTorchOn: (bool) on {
Class captureDeviceClass = NSClassFromString(@"AVCaptureDevice");
if (captureDeviceClass != nil) {
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if ([device hasTorch] && [device hasFlash]){
[device lockForConfiguration:nil];
if (on) {
[device setTorchMode:AVCaptureTorchModeOn];
[device setFlashMode:AVCaptureFlashModeOn];
} else {
[device setTorchMode:AVCaptureTorchModeOff];
[device setFlashMode:AVCaptureFlashModeOff];
}
[device unlockForConfiguration];
}
}
}
但是當我打開APP和前置攝像頭出現在LED熄滅。 我需要同時工作。
謝謝
到目前爲止這個運氣還好嗎? – 2014-10-11 14:32:07
沒有:(看起來像蘋果可以做到這一點,因爲如果你意識到蘋果手電筒不像所有其他手電筒應用程序一樣訪問攝像頭 – rendellhb 2014-10-14 21:04:29
@rendellhb:我想在android.do中使用相同的功能。你知道這可能嗎? – Basher51 2014-11-08 15:45:19