繁体   English   中英

iOS相机AVCaptureSession为人像,具有横向尺寸或分辨率

[英]iOS camera AVCaptureSession in portrait with landscape size or resolution

我以纵向模式创建了AVCaptureVideoPreviewLayer,我想知道如何在保持纵向模式的同时以16:9比例(横向宽高比)显示它

我试过了:

1.给摄像头PreviewLayer 16:9尺寸,但显示为缩放

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

我想将相机倾斜为具有风景纵横比的肖像或具有风景纵横比的肖像相机

计算宽高比,然后相应地缩放图像。

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!
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM