gpt4 book ai didi

ios - iPhone 6有前置闪光灯吗

转载 作者:行者123 更新时间:2023-11-30 13:05:27 28 4
gpt4 key购买 nike

当我为前置摄像头设置闪光模式然后调用时

让 videoConnection = stillImageOutput!.connectionWithMediaType(AVMediaTypeVideo) stillImageOutput?.captureStillImageAsynchronouslyFromConnection(videoConnection,completionHandler:过程)我收到以下错误消息:

捕获静态图像时出错:Error Domain=AVFoundationErrorDomain Code=-11800“操作无法完成”UserInfo={NSUnderlyingError=0x12eeb7200 {Error Domain=NSOSStatusErrorDomain Code=-16800“(null)”},NSLocalizedFailureReason=An发生未知错误 (-16800),NSLocalizedDescription=操作无法完成}

如果我不设置相机的flashMode然后调用:

let videoConnection = stillImageOutput!.connectionWithMediaType(AVMediaTypeVideo)
stillImageOutput?.captureStillImageAsynchronouslyFromConnection(videoConnection, completionHandler: process)

前置摄像头拍照并没有抛出错误。所以我想知道,iPhone 是否有前置摄像头闪光灯?应该考虑到 Snapchat 有一个。 iPhone 上的默认相机应用程序具有前置摄像头闪光灯。所以我不完全确定发生了什么事。目前,这就是我设置相机的方式:

func getCameraStreamLayer() -> CALayer? {

captureSession = AVCaptureSession()
captureSession!.sessionPreset = AVCaptureSessionPresetPhoto
currentCamera = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)
stillImageOutput = AVCaptureStillImageOutput()
stillImageOutput!.outputSettings = [ AVVideoCodecKey: AVVideoCodecJPEG ]

if let input = try? AVCaptureDeviceInput(device: currentCamera) as AVCaptureDeviceInput{
if captureSession!.canAddInput(input) && captureSession!.canAddOutput(stillImageOutput) {
captureSession!.addInput(input)
captureSession!.addOutput(stillImageOutput)
}
}

return AVCaptureVideoPreviewLayer(session: captureSession)

}

func toggleFlash() {
flash = !flash
if flash {
for case let (device as AVCaptureDevice) in AVCaptureDevice.devices() {
if device.hasFlash && device.flashAvailable {
if device.isFlashModeSupported(.On) {
do {
try device.lockForConfiguration()
device.flashMode = .On
device.unlockForConfiguration()


} catch {
print("Something went wrong")
}
}
}
}
}else {//turn off flash
}
}


func photograph(process: (CMSampleBuffer!,NSError!)->()) {
let videoConnection = stillImageOutput!.connectionWithMediaType(AVMediaTypeVideo)
stillImageOutput?.captureStillImageAsynchronouslyFromConnection(videoConnection, completionHandler: process)

}
func flipCamera() {
guard let session = captureSession where session.running == true else {
return
}

session.beginConfiguration()
let currentCameraInput = session.inputs[0] as! AVCaptureDeviceInput
session.removeInput(currentCameraInput)


let newCamera = {
let devices = AVCaptureDevice.devicesWithMediaType(AVMediaTypeVideo)
for case let device as AVCaptureDevice in devices {
if(device.position == .Front && currentCameraInput.device.position == .Back){
return device
}
if(device.position == .Back && currentCameraInput.device.position == .Front){
return device
}
}
return nil
}() as AVCaptureDevice?
currentCamera = newCamera!
if let newVideoInput = try? AVCaptureDeviceInput(device: newCamera) {
captureSession?.addInput(newVideoInput)
}

captureSession?.commitConfiguration()
}

我不知道我应该做什么。我尝试创建一个新的捕获 session ,然后锁定并设置相机的 flashMode。我仍然遇到同样的错误。

最佳答案

iPhone 6 没有前置闪光灯摄像头,但 iPhone 6s 及更高版本有。

应用商店中有一些“黑客”解决方案,可以使屏幕明亮地闪烁以在前置模式下产生光线,但没有实际的闪光。

关于ios - iPhone 6有前置闪光灯吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39436998/

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