Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios AVCaptureStillImageOutput和AVCaptureVideoPreviewLayer图像大小不一致_Ios_Swift_Cocoa Touch_Avfoundation_Avcapturesession - Fatal编程技术网

Ios AVCaptureStillImageOutput和AVCaptureVideoPreviewLayer图像大小不一致

Ios AVCaptureStillImageOutput和AVCaptureVideoPreviewLayer图像大小不一致,ios,swift,cocoa-touch,avfoundation,avcapturesession,Ios,Swift,Cocoa Touch,Avfoundation,Avcapturesession,我现在正面临一个让我发疯的问题 我有一个应用程序,它有一个AVCaptureVideoPreviewLayer来显示摄像头,类似于snapchat 当我通过AVCaptureStillImageOutput拍摄静态图片时,它比预览层宽得多 我想实现的是,在拍摄照片后,根据大小,拍摄的照片与预览中的照片看起来是1:1 func takePicture(){ if let videoConnection = stillImageOutput.connectionWithMediaTy

我现在正面临一个让我发疯的问题

我有一个应用程序,它有一个AVCaptureVideoPreviewLayer来显示摄像头,类似于snapchat

当我通过AVCaptureStillImageOutput拍摄静态图片时,它比预览层宽得多

我想实现的是,在拍摄照片后,根据大小,拍摄的照片与预览中的照片看起来是1:1

    func takePicture(){
    if let videoConnection = stillImageOutput.connectionWithMediaType(AVMediaTypeVideo) {

        // make sure we have the proper device orientation set
        videoConnection.videoOrientation = previewLayer!.connection!.videoOrientation

        stillImageOutput.captureStillImageAsynchronouslyFromConnection(videoConnection) {
            (imageDataSampleBuffer, error) -> Void in
            // take the picture from output
            let imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(imageDataSampleBuffer)
            let imageOriginal:UIImage = UIImage(data: imageData)!

            // imageOriginal must have the same aspect and size as the previewLayer!

        }
    }
}
我已经尝试过基于计算的方面进行裁剪,但这不起作用

Previewlayer设置了重力准备就绪

previewLayer?.videoGravity = AVLayerVideoGravityResizeAspectFill
这不会改变任何事情,我认为错误在于stillImageOutput,而不是预览层

如果有人知道帮助会很好,那么整个AVFoundation主题在www上似乎很少涉及

如果有人不明白我的意思,请查看snapchat的两个屏幕截图