I use -writeImageToSavedPhotosAlbum to send images to the Photo Library. The problem I am facing is that, despite indicating the orientation, the images end up with incorrect orientations.
Actually, those that are oriented by AVCaptureVideoOrientationPortrait look like AVCaptureVideoOrientationPortraitUpsideDown , and AVCaptureVideoOrientationLandscapeLeft look like AVCaptureVideoOrientationLandscapeRight and vice versa.
Is there a reason why this is happening? Here are some more details:
I do not have a ViewController that does an automatic orientation change for my view.
All images show [image imageOrientation] equal to AVCaptureVideoOrientationPortrait , but I keep track of the actual orientation and pass this to -writeImageToSavedPhotosAlbum independently.
I use: -writeImageToSavedPhotosAlbum:orientation:completionBlock:
I would appreciate it if someone could shed light on this.
UPDATE:
Despite the fact that I read in the documentation,
If you want to save the UIImage object, you can use the UIImage CGImage method to get the CGImageRef, and discard imageOrientation images to ALAssetOrientation.
I went ahead and changed the orientation in which I walked:
switch (lastOrientation) { case UIDeviceOrientationPortrait: default: alOrientation = ALAssetOrientationUp; break; case UIDeviceOrientationPortraitUpsideDown: alOrientation = ALAssetOrientationDown; break; case UIDeviceOrientationLandscapeLeft: alOrientation = ALAssetOrientationLeft; break; case UIDeviceOrientationLandscapeRight: alOrientation = ALAssetOrientationRight; break; } [library writeImageToSavedPhotosAlbum:[image CGImage] orientation:(ALAssetOrientation) alOrientation
Now all the images are oriented with the left edge down, as if they were landscape. I still do not have the right, but at least for me they are uniformly oriented.
Other UPDATE:
It works. Why i do not know:
switch (lockedOrientation) { case UIDeviceOrientationPortrait: default: alOrientation = ALAssetOrientationRight; //3 instead ofALAssetOrientationUp; break; case UIDeviceOrientationPortraitUpsideDown: alOrientation = ALAssetOrientationLeft; //2 insted of ALAssetOrientationDown; break; case UIDeviceOrientationLandscapeLeft: alOrientation = ALAssetOrientationUp; //0 instead of ALAssetOrientationLeft; break; case UIDeviceOrientationLandscapeRight: alOrientation = ALAssetOrientationDown; //1 instead of ALAssetOrientationRight; break; } [library writeImageToSavedPhotosAlbum:[image CGImage] orientation:(ALAssetOrientation) alOrientation// [image imageOrientation] completionBlock:^(NSURL *assetURL, NSError *error) { NSLog(@"completion block"); }];