应用 CIFilter 后,UIImage 被旋转 90 度。我很惊讶这个问题在这么多年后仍然发生。这些修复是否有快速版本:
更好的修复: iOS UIImagePickerController result image orientation after upload
原始修复: Using CoreImage to filter an image results in image rotation
最佳答案
这个怎么样(其中image
是你的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
}
}
关于objective-c - CIFilter 在 Swift 中旋转 UIImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28975554/