1
當我用這個方法拍攝一張照片從我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)
}
})
}
請告訴我,如果需要更多信息。謝謝!