相关疑难解决方法(0)

为什么AVCaptureVideoOrientation横向模式会导致静止图像颠倒?

我正在使用AVFoundation类在我的应用程序中实现自定义相机.我只捕捉静止图像,而不是视频.我有一切工作,但我被一些东西困扰.我会在捕获静止图像时考虑设备方向,并适当地设置视频连接的videoOrientation.代码段:

    // set the videoOrientation based on the device orientation to
    // ensure the pic is right side up for all orientations
    AVCaptureVideoOrientation videoOrientation;
    switch ([UIDevice currentDevice].orientation) {
        case UIDeviceOrientationLandscapeLeft:
            // Not clear why but the landscape orientations are reversed
            // if I use AVCaptureVideoOrientationLandscapeLeft here the pic ends up upside down
            videoOrientation = AVCaptureVideoOrientationLandscapeRight;
            break;
        case UIDeviceOrientationLandscapeRight:
            // Not clear why but the landscape orientations are reversed
            // if I use AVCaptureVideoOrientationLandscapeRight here the pic ends up upside down …
Run Code Online (Sandbox Code Playgroud)

iphone image-capture ios avcapturesession avcapturedevice

7
推荐指数
2
解决办法
1万
查看次数

imageOrientation返回Up,但照片显示倒置

我正在从iPad照片库中抓取一些照片.我在横向模式下拍了几张测试照片,左边是iPad主页按钮,右边是.

所以在我的应用程序中,由于某种原因,一些照片显示出颠倒.我检查了他们的imageOrientation财产,他们都是0(意思是他们UIImageOrientationUp).这意味着我甚至不知道我需要旋转哪些照片.

发生了什么,我怎么知道哪些照片需要旋转?谢谢

iphone xcode ipad ios

7
推荐指数
1
解决办法
836
查看次数

Swift - AVFoundation 捕获图像方向

我有一个自定义相机,可以在人像模式下拍照。

我的问题是,如果我尝试以横向方式拍摄照片并保存,那么图片仍会以纵向模式保存。

我有这个功能来设置预览层:

 static func setupPreviewLayer(view: UIView) {
    cameraPreviewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
    cameraPreviewLayer?.videoGravity = AVLayerVideoGravity.resizeAspectFill
    switch UIDevice.current.orientation {
    case .portrait:
        cameraPreviewLayer?.connection?.videoOrientation = 
       AVCaptureVideoOrientation.portrait
    case .portraitUpsideDown:
        cameraPreviewLayer?.connection?.videoOrientation = 
          AVCaptureVideoOrientation.portraitUpsideDown
    case .landscapeLeft:
        cameraPreviewLayer?.connection?.videoOrientation =
        AVCaptureVideoOrientation.landscapeLeft
    case .landscapeRight:
        cameraPreviewLayer?.connection?.videoOrientation = 
         AVCaptureVideoOrientation.landscapeRight
    default:
        cameraPreviewLayer?.connection?.videoOrientation = 
         AVCaptureVideoOrientation.portrait
    }
    cameraPreviewLayer?.frame = view.frame
    view.layer.insertSublayer(cameraPreviewLayer!, at: 0)
}
Run Code Online (Sandbox Code Playgroud)

我称之为 viewWillAppear (我认为这不是正确的做法)。

然后我拍了张照片:

@IBAction func takePhotoBtnPressed(_ sender: Any) {
    let settings = AVCapturePhotoSettings()
    useFlash(settings: settings)
    settings.isAutoStillImageStabilizationEnabled = true
    CustomCamera.photoOutput?.capturePhoto(with: settings, delegate: self)
}
Run Code Online (Sandbox Code Playgroud)

并使用此扩展名:

extension FishCameraVC: AVCapturePhotoCaptureDelegate {
func …
Run Code Online (Sandbox Code Playgroud)

avfoundation ios landscape-portrait swift

3
推荐指数
2
解决办法
7669
查看次数