2

After applying CIFilter, the UIImage is being rotated 90 degrees. I'm surprised this issue is still happening after so many years. Is there a swift version of these fixes:

Better Fix: iOS UIImagePickerController result image orientation after upload

Original Fix: Using CoreImage to filter an image results in image rotation

Community
  • 1
  • 1
Onichan
  • 4,476
  • 6
  • 31
  • 60
  • Possible duplicate of [Image auto-rotates after using CIFilter](http://stackoverflow.com/questions/24833285/image-auto-rotates-after-using-cifilter) – user4812000 Feb 11 '16 at 06:03

1 Answers1

2

How about this (where image is your UIImage):

let ciImage = CIImage(image: image)?.imageByApplyingOrientation(imageOrientationToTiffOrientation(image.imageOrientation))

func imageOrientationToTiffOrientation(value: UIImageOrientation) -> Int32
{
    switch (value)
    {
    case UIImageOrientation.Up:
        return 1
    case UIImageOrientation.Down:
        return 3
    case UIImageOrientation.Left:
        return 8
    case UIImageOrientation.Right:
        return 6
    case UIImageOrientation.UpMirrored:
        return 2
    case UIImageOrientation.DownMirrored:
        return 4
    case UIImageOrientation.LeftMirrored:
        return 5
    case UIImageOrientation.RightMirrored:
        return 7
    }
}
Flex Monkey
  • 3,583
  • 17
  • 19