【问题标题】:iOS camera AVCaptureSession in portrait with landscape size or resolutioniOS 相机 AVCaptureSession 在纵向与横向大小或分辨率
【发布时间】:2018-08-03 06:07:55
【问题描述】:

我在纵向模式下创建了 AVCaptureVideoPreviewLayer,我想知道如何在纵向模式下以 16:9 比例(横向纵横比)显示它

我试过了:

1.Giving camera PreviewLayer 16:9 size 但它显示为缩放

2.我尝试在这里使用videoPreviewLayer?.connection?.videoOrientation = AVCaptureVideoOrientation.landscape,分辨率完美,但显示为旋转图像(风景相机)

我想将相机倾斜到具有横向纵横比的纵向或 具有横向纵横比的人像相机

【问题讨论】:

    标签: ios swift avfoundation ios-camera avcapture


    【解决方案1】:

    计算纵横比,然后相应地缩放图像..

    func imageWithImage (sourceImage:UIImage, scaledToWidth: CGFloat) -> UIImage {
        let oldWidth = sourceImage.size.width
        let scaleFactor = scaledToWidth / oldWidth
    
        let newHeight = sourceImage.size.height * scaleFactor
        let newWidth = oldWidth * scaleFactor
    
        UIGraphicsBeginImageContext(CGSize(width:newWidth, height:newHeight))
        sourceImage.draw(in: CGRect(x:0, y:0, width:newWidth, height:newHeight))
        let newImage = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return newImage!
    }
    

    【讨论】:

    • 感谢您的回答,但我尝试使用 AVCaptureSession 的实时摄像头出现在横向分辨率(水平帧 16:9 比例)的 AVCaptureVideoPreviewLayer 中,同时保持纵向模式。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多