不保存所需的图像方向

Doesn't Save Desired Image Orientation

当我使用这种方法从我的 AVCaptureSession 中拍照时...

func didPressTakePhoto(){
    toggleFlash()

    if let videoConnection = stillImageOutput?.connectionWithMediaType(AVMediaTypeVideo){
        videoConnection.videoOrientation = AVCaptureVideoOrientation.Portrait
        stillImageOutput?.captureStillImageAsynchronouslyFromConnection(videoConnection, completionHandler: {
            (sampleBuffer, error) in

            if sampleBuffer != nil {
                let imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(sampleBuffer)
                self.capturedImage = UIImage(data: imageData)

                if self.camera == true {
                    self.capturedImage = UIImage(CGImage: self.capturedImage.CGImage!, scale: 1.0, orientation: UIImageOrientation.Right)


                } else {
                    self.capturedImage = UIImage(CGImage: self.capturedImage.CGImage!, scale: 1.0, orientation: UIImageOrientation.LeftMirrored)

                }

                self.tempImageView.clipsToBounds = true
                self.tempImageView.image = self.capturedImage
                self.tempImageView.hidden = false
                self.goButton.hidden = false
                self.cameraView.hidden = true
                self.removeImageButton.hidden = false
                self.captureButton.hidden = true

            }


        })
    }
}

我旋转图像以固定方向,使其看起来像在图像视图中应该看起来的样子。当我将它另存为 PFFile 进行解析时,它向左旋转 90 度,完全弄乱了方向。这是我保存图像以进行解析的地方...

@IBAction func go(sender: UIButton) {
    let newUser = PFUser()
    newUser["email"] = emailString
    newUser.password = passwordString
    newUser.username = usernameString

    let imageData = UIImagePNGRepresentation(tempImageView.image)

    let imageFile = PFFile(name: "avatar.png", data: imageData!)

    newUser["avatar"] = imageFile

    newUser.signUpInBackgroundWithBlock({ (success, error) -> Void in
        if success != true {

            let signUpAlert = UIAlertController(title: "Couldn't Sign Up!", message:
                "An error occured please try again.", preferredStyle: UIAlertControllerStyle.Alert)

            signUpAlert.addAction(UIAlertAction(title: "Try Again", style: .Default, handler: { (action: UIAlertAction!) -> Void in
                sender.sendActionsForControlEvents(.TouchUpInside)
            }))

            signUpAlert.addAction(UIAlertAction(title: "Cancel", style: .Default, handler: { (action: UIAlertAction!) -> Void in
            }))


            self.presentViewController(signUpAlert, animated: true, completion: nil)

        }

    })

}

如果需要更多信息,请告诉我。谢谢!

Parse 未对您的图像执行任何操作。当您在 UIImage 中旋转 JPEG 图像时,JPEG 图像数据不会被旋转。相反,方向​​存储在其 EXIF 元数据中。当您将图像转换为 PNG 以保存在 Prase 上时,EXIF 元数据会丢失,因为 PNG 不存储任何方向元数据信息。为了以正确的方向和镜像获取图像,请在捕获图像之前为您的视频连接设置正确的方向和镜像属性。或者,您可以将图像存储为 JPEG 而不是 PNG。