我创建的AVCaptureVideoPreviewLayer在纵向模式,我想知道如何显示它在16:9的比例(横向纵横比),而举行的纵向模式
我试过了:
1.指定摄像头PreviewLayer的大小为16:9,但显示为缩放
2.我尝试在这里使用videoPreviewLayer?.connection?.videoOrientation = AVCaptureVideoOrientation.landscape分辨率很完美,但它显示为旋转图像(风景相机)
我想倾斜相机到肖像与横向纵横比或肖像相机与横向aspectRatio
发布于 2018-08-03 18:38:36
计算宽高比,然后相应地缩放图像。
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!
}https://stackoverflow.com/questions/51666255
复制相似问题