Skip to content

Instantly share code, notes, and snippets.

@npinto
Created January 31, 2013 09:05
Show Gist options
  • Select an option

  • Save npinto/4681505 to your computer and use it in GitHub Desktop.

Select an option

Save npinto/4681505 to your computer and use it in GitHub Desktop.

Revisions

  1. npinto created this gist Jan 31, 2013.
    36 changes: 36 additions & 0 deletions exifOrientation.mm
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    UIDeviceOrientation curDeviceOrientation = [[UIDevice currentDevice] orientation];

    enum {
    PHOTOS_EXIF_0ROW_TOP_0COL_LEFT = 1, // 1 = 0th row is at the top, and 0th column is on the left (THE DEFAULT).
    PHOTOS_EXIF_0ROW_TOP_0COL_RIGHT = 2, // 2 = 0th row is at the top, and 0th column is on the right.
    PHOTOS_EXIF_0ROW_BOTTOM_0COL_RIGHT = 3, // 3 = 0th row is at the bottom, and 0th column is on the right.
    PHOTOS_EXIF_0ROW_BOTTOM_0COL_LEFT = 4, // 4 = 0th row is at the bottom, and 0th column is on the left.
    PHOTOS_EXIF_0ROW_LEFT_0COL_TOP = 5, // 5 = 0th row is on the left, and 0th column is the top.
    PHOTOS_EXIF_0ROW_RIGHT_0COL_TOP = 6, // 6 = 0th row is on the right, and 0th column is the top.
    PHOTOS_EXIF_0ROW_RIGHT_0COL_BOTTOM = 7, // 7 = 0th row is on the right, and 0th column is the bottom.
    PHOTOS_EXIF_0ROW_LEFT_0COL_BOTTOM = 8 // 8 = 0th row is on the left, and 0th column is the bottom.
    };

    int exifOrientation;
    switch (curDeviceOrientation) {
    case UIDeviceOrientationPortraitUpsideDown: // Device oriented vertically, home button on the top
    exifOrientation = PHOTOS_EXIF_0ROW_LEFT_0COL_BOTTOM;
    break;
    case UIDeviceOrientationLandscapeLeft: // Device oriented horizontally, home button on the right
    if (UserDefaults.usingFrontCamera)
    exifOrientation = PHOTOS_EXIF_0ROW_BOTTOM_0COL_RIGHT;
    else
    exifOrientation = PHOTOS_EXIF_0ROW_TOP_0COL_LEFT;
    break;
    case UIDeviceOrientationLandscapeRight: // Device oriented horizontally, home button on the left
    if (UserDefaults.usingFrontCamera)
    exifOrientation = PHOTOS_EXIF_0ROW_TOP_0COL_LEFT;
    else
    exifOrientation = PHOTOS_EXIF_0ROW_BOTTOM_0COL_RIGHT;
    break;
    case UIDeviceOrientationPortrait: // Device oriented vertically, home button on the bottom
    default:
    exifOrientation = PHOTOS_EXIF_0ROW_RIGHT_0COL_TOP;
    break;
    }