gpt4 book ai didi

ios - 如何为图像捕捉计时相机闪光灯?

转载 作者:搜寻专家 更新时间:2023-11-01 07:30:04 25 4
gpt4 key购买 nike

我想在拍照时让我的闪光灯同步,但不确定如何。我尝试过使用 NSTimer 和 NSSleep 以及其他计时方式,但由于有时相机对焦和拍照的时间比其他时间长,所以闪光灯并不总是完全正确。我将如何做到这一点?

这是我如何制作闪光灯...

func toggleFlash() {
let device = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)
if (device.hasTorch) {
device.lockForConfiguration(nil)
if (device.torchMode == AVCaptureTorchMode.On) {
device.torchMode = AVCaptureTorchMode.Off
} else {
device.setTorchModeOnWithLevel(1.0, error: nil)
}
device.unlockForConfiguration()
}
}

这就是我拍照的方式......

func didPressTakePhoto(){

if let videoConnection = stillImageOutput?.connectionWithMediaType(AVMediaTypeVideo){
videoConnection.videoOrientation = AVCaptureVideoOrientation.Portrait
stillImageOutput?.captureStillImageAsynchronouslyFromConnection(videoConnection, completionHandler: {
(sampleBuffer, error) in

if sampleBuffer != nil {

var imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(sampleBuffer)
var dataProvider = CGDataProviderCreateWithCFData(imageData)
var cgImageRef = CGImageCreateWithJPEGDataProvider(dataProvider, nil, true, kCGRenderingIntentDefault)

var image:UIImage!

if self.camera == true {
image = UIImage(CGImage: cgImageRef, scale: 1.0, orientation: UIImageOrientation.Right)

} else {
image = UIImage(CGImage: cgImageRef, scale: 1.0, orientation: UIImageOrientation.LeftMirrored)

}

self.tempImageView.image = image
self.tempImageView.hidden = false

}


})
}


}

最佳答案

toggleFlash中需要设置

device.flashMode = .On

您正在设置 torchMode

更正此问题应该会使闪光灯在 captureStillImageAsynchronouslyFromConnection 期间的正确时间熄灭。

关于ios - 如何为图像捕捉计时相机闪光灯?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33115975/

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