Ios 使用AVCaptureSession以编程方式捕获最大分辨率图像
我的目标是使用Ios 使用AVCaptureSession以编程方式捕获最大分辨率图像,ios,iphone,swift,camera,avfoundation,Ios,Iphone,Swift,Camera,Avfoundation,我的目标是使用AVCaptureSession以编程方式锁定焦点,捕获一个图像,激活闪光灯,然后在延迟一段时间后捕获第二个图像 我已经使用AVCaptureSession实例和AVCaptureStillImageOutput使捕获工作正常。但是,当我从Connection(u:completionHandler:)异步调用captureStillImageAsynchronouslyFromConnection(\uuuxCompletionHandler:)时获得的图像是1920 x 108
AVCaptureSession
以编程方式锁定焦点,捕获一个图像,激活闪光灯,然后在延迟一段时间后捕获第二个图像
我已经使用AVCaptureSession
实例和AVCaptureStillImageOutput
使捕获工作正常。但是,当我从Connection(u:completionHandler:)异步调用captureStillImageAsynchronouslyFromConnection(\uuuxCompletionHandler:)时获得的图像是1920 x 1080,而不是我的iPhone 6S相机能够获得的1200万像素的完整图像
以下是我的捕获功能:
func captureImageFromStream(completion: (result: UIImage) -> Void)
{
if let stillOutput = self.stillImageOutput {
var videoConnection : AVCaptureConnection?
for connection in stillOutput.connections {
for port in connection.inputPorts! {
if port.mediaType == AVMediaTypeVideo {
videoConnection = connection as? AVCaptureConnection
break
}
}
if videoConnection != nil {
break
}
}
if videoConnection != nil {
stillOutput.captureStillImageAsynchronouslyFromConnection(videoConnection) {
(imageDataSampleBuffer, error) -> Void in
if error == nil {
let imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(imageDataSampleBuffer)
if let image = UIImage(data: imageData) {
completion(result: image)
}
}
else {
NSLog("ImageCapture Error: \(error)")
}
}
}
}
}
我应该做哪些修改来捕获我要寻找的图像?我是Swift新手,因此请原谅我犯的任何初学者错误。在
添加输出
之前,您需要将捕获会话预设设置为照片:
captureSession.sessionPreset = AVCaptureSessionPresetPhoto
工作得很好。谢谢