gpt4 book ai didi

ios - 捕获后如何更改图像的方向?

转载 作者:行者123 更新时间:2023-11-28 10:56:55 24 4
gpt4 key购买 nike

这是我在自定义相机中用于拍摄照片的代码,但它可以正确拍摄照片,但如果假设用户旋转设备(但相机仍会像 iphone 相机一样纵向拍摄)并拍照,我想要纵向拍摄照片。怎么能我这样做?

        let stillImageOutput = self._getStillImageOutput()

if let videoConnection = stillImageOutput.connection(withMediaType: AVMediaTypeVideo) {

// videoConnection.videoOrientation = AVCaptureVideoOrientation.portrait

stillImageOutput.captureStillImageAsynchronously(from: videoConnection , completionHandler: { [weak self] sample, error in

if let error = error {
DispatchQueue.main.async(execute: {
self?._show(NSLocalizedString("Error", comment:""), message: error.localizedDescription)
})
imageCompletion(nil,error as NSError?)
return
}

let imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(sample)

var capturedImage = UIImage(data: imageData!)[![This how photo showing if i capture by rotating Device][1]][1]

This image i want in portrait

最佳答案

在初始化 videoConnection 之后添加下面的代码就可以了

switch UIDevice.current.orientation {
case .landscapeLeft:
videoConnection.videoOrientation = AVCaptureVideoOrientation.landscapeRight
break
case .landscapeRight:
videoConnection.videoOrientation = AVCaptureVideoOrientation.landscapeLeft
break
case .portrait:
videoConnection.videoOrientation = AVCaptureVideoOrientation.portrait
break
case .portraitUpsideDown:
videoConnection.videoOrientation = AVCaptureVideoOrientation.portraitUpsideDown
break
default:
videoConnection.videoOrientation = AVCaptureVideoOrientation.portrait
break
}

关于ios - 捕获后如何更改图像的方向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42918053/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com