gpt4 book ai didi

ios - 在 iPhone 上同时打开闪光灯和前置摄像头

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:37:57 26 4
gpt4 key购买 nike

我需要使用前置摄像头并在 iPhone 中打开背光 LED。我怎样才能做到这一点?我可以使用此代码打开前置摄像头:

- (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 熄灭。我需要两者同时工作。

谢谢

最佳答案

iOS 当前的 API 集不允许这样做。你可以通过苹果自己的相机应用程序来理解这一点。

甚至当您切换到使用前置摄像头时,它们也会关闭手电筒,并且在该模式下不显示手电筒开关。

关于ios - 在 iPhone 上同时打开闪光灯和前置摄像头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26173182/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com