gpt4 book ai didi

objective-c - CIFilter 在 Swift 中旋转 UIImage

转载 作者:行者123 更新时间:2023-11-28 05:30:22 26 4
gpt4 key购买 nike

应用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com