title: Updating UIImage orientation metaData?
body: <p><strong>Basic Task:</strong> update the EXIF orientation property for the metaData asociated with a UIImage. My problem is that I don't know where the orientation property is in all the EXIF info.</p>
  
  <hr>
  
  <p><strong>Convoluted Background:</strong> I am changing the orientation of the image returned by <code>imagePickerController:didFinishPickingMediaWithInfo:</code> so I am thinking that I also need to update the metaData before saving the image with <code>writeImageToSavedPhotosAlbum:(CGImageRef)imageRef metadata:(NSDictionary *)metadata</code>.</p>
  
  <p>In other words, unless I change it, the metaData will contain the old/initial orientation and thus be wrong. The reason I am changing the orientation is because it keeps tripping me up when I run the <code>Core Image</code> face detection routine. Taking a photo with the iPhone (device) in Portrait mode using the front camera, the orientation is <code>UIImageOrientationRight</code> (3). If I rewrite the image so the orientation is <code>UIImageOrientationUp</code>(0), I get good face detection results. For reference, the routine to rewrite the image is below.</p>
  
  <p>The whole camera orientation thing I find very confusing and I seem to be digging myself deeper into a code hole with all of this. I have looked at the posts (<a href="https://stackoverflow.com/questions/11520209/how-to-update-exif-of-alasset-without-changing-the-image">here</a>, <a href="https://stackoverflow.com/questions/5125323/problem-setting-exif-data-for-an-image">here</a> and <a href="http://blog.codecropper.com/2011/05/adding-metadata-to-ios-images-the-easy-way/" rel="nofollow noreferrer">here</a>. And according to this post (<a href="https://stackoverflow.com/a/3781192/840992">https://stackoverflow.com/a/3781192/840992</a>):</p>
  
  <blockquote>
    <p>"The camera is actually landscape native, so you get up or down when
    you take a picture in landscape and left or right when you take a
    picture in portrait (depending on how you hold the device)."</p>
  </blockquote>
  
  <p>...which is totally confusing. If the above is true, I would think I should be getting an orientation of <code>UIImageOrientationLeftMirrored</code> or <code>UIImageOrientationRightMirrored</code> with the front camera. And none of this would explain why the <code>CIDetector</code> fails the virgin image returned by the picker.</p>
  
  <p>I am approaching this ass-backwards but I can't seem to get oriented...</p>
  
  <hr>
  
  <pre><code>-(UIImage *)normalizedImage:(UIImage *) thisImage
  {
      if (thisImage.imageOrientation == UIImageOrientationUp) return thisImage;
  
      UIGraphicsBeginImageContextWithOptions(thisImage.size, NO, thisImage.scale);
      [thisImage drawInRect:(CGRect){0, 0, thisImage.size}];
      UIImage *normalizedImage = UIGraphicsGetImageFromCurrentImageContext();
      UIGraphicsEndImageContext();
      return normalizedImage;
  }
  </code></pre>