![](/img/trans.png)
[英]capture image from iphone camera or get it from library, How to get the image capture time?
[英]How to time camera flash with image capture?
我想这样做,以使我的闪光灯在拍摄照片时会与时间同步,但不确定如何拍摄。 我尝试过使用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
。
纠正此问题应使flash在captureStillImageAsynchronouslyFromConnection
期间的正确时间熄灭。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.