[英]Custom camera aspect ratio
我正在使用以下代碼通過AVFoundation
創建自定義攝像機視圖:
captureSession.addInput(AVCaptureDeviceInput(device: captureDevice, error: &err))
captureSession.addOutput(stillOutput)
if err != nil {
println("error: \(err?.localizedDescription)")
}
previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
previewLayer?.videoGravity=AVLayerVideoGravityResizeAspectFill
而且效果很好。 然后,我使用以下代碼捕獲並在屏幕上顯示圖像:
self.stillOutput.captureStillImageAsynchronouslyFromConnection(videoConnection){
(imageSampleBuffer : CMSampleBuffer!, _) in
let imageDataJpeg = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(imageSampleBuffer)
var pickedImage: UIImage = UIImage(data: imageDataJpeg)!
var previewImageView=UIImageView()
self.previewImageView.frame = CGRect(x:0, y:0, width:UIScreen.mainScreen().bounds.width, height:UIScreen.mainScreen().bounds.height)
self.previewImageView.layer.zPosition = -1
self.view.addSubview(self.previewImageView)
但是當我想顯示預覽圖像時,相機可以正常工作:
相機:
鏡頭預覽后:
它看起來應該像相機視圖。 我該如何解決?
如果要使縱橫比為3:4
,則應設置:
captureSession.sessionPreset = .photo
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.