title: Why does -writeImageToSavedPhotosAlbum orient my picture incorrectly?
body: <p>I am using <code>-writeImageToSavedPhotosAlbum</code> to sent images to the Photo Library.  The problem I am having is that despite specifying an orientation, the images end up with the wrong orientations.  </p>
  
  <p>In fact, it seems that ones that are oriented <code>AVCaptureVideoOrientationPortrait</code> end up looking like <code>AVCaptureVideoOrientationPortraitUpsideDown</code>,
  and <code>AVCaptureVideoOrientationLandscapeLeft</code> end up looking like <code>AVCaptureVideoOrientationLandscapeRight</code> and vice versa.  </p>
  
  <p>Is there some reason why this is happening?  Here are some more details:</p>
  
  <p>I have no ViewController doing the automatic orientation change for my view.<br>
  All images show <code>[image imageOrientation]</code> equal to <code>AVCaptureVideoOrientationPortrait</code>, but I keep track of the actual orientation and pass that in to <code>-writeImageToSavedPhotosAlbum</code> independently.</p>
  
  <p>I'm using: <code>-writeImageToSavedPhotosAlbum:orientation:completionBlock:</code></p>
  
  <p>I'd appreciate it if someone could shed some light onto this.</p>
  
  <p>UPDATE:</p>
  
  <p>Despite what I read in the documentation, </p>
  
  <blockquote>
    <p>If you want to save a UIImage object, you can use the UIImage method
    CGImage to get a CGImageRef, and cast the image’s imageOrientation to
    ALAssetOrientation.</p>
  </blockquote>
  
  <p>I went ahead and changed the orientation I pass in:</p>
  
  <pre><code>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// [image imageOrientation]
                        completionBlock:^(NSURL *assetURL, NSError *error) {
                              NSLog(@"completion block");
                        }];
  </code></pre>
  
  <p>Now, all images get oriented with their left edge down, as if they are landscape-right.  I still don't have it right, but at least I have them uniformly oriented.</p>
  
  <p>Another UPDATE:</p>
  
  <p>This works.  Why, I don't know:</p>
  
  <pre><code>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");
                            }];
  </code></pre>