CIFilter 已更改 UIImage 纵横比 - SWIFT
CIFilter has changed UIImage Aspect Ratio - SWIFT
我已经在我的 iOS 应用程序中为 profileImages 实现了 CIFilter。我添加了方向以防止像素化,但我的 宽高比 "ScaleAspectFill" 未应用于图像。相同颜色的图像具有完美的纵横比……即当我只有:
self.p1ProfilePic.image = p1Img
- 我已经在 Storyboard 中为个人资料图片指定了准确的高度和宽度。
- 我尝试以编程方式将 .contentMode 添加为 .ScaleAspectFill,但没有任何效果。
我在这里错过了什么? CGRect?
let originalImageP1 = CIImage(image: p1Img!)
let filter = CIFilter(name: "CIPhotoEffectTonal")
filter!.setDefaults()
filter!.setValue(originalImageP1, forKey: kCIInputImageKey)
let outputImage = filter!.outputImage
self.p1ProfilePic.image = UIImage(CIImage: outputImage!, scale: UIScreen.mainScreen().scale, orientation: .Up)
使用您的技术从 CIImage
创建 UIImage
会创建不符合 contentMode
的图像。试试这个:
let ciContext = CIContext()
let cgImage = ciContext.createCGImage(filter.outputImage!,
fromRect: filter.outputImage!.extent)
self.p1ProfilePic.image = UIImage(CGImage: cgImage)
干杯!
西蒙
我已经在我的 iOS 应用程序中为 profileImages 实现了 CIFilter。我添加了方向以防止像素化,但我的 宽高比 "ScaleAspectFill" 未应用于图像。相同颜色的图像具有完美的纵横比……即当我只有:
self.p1ProfilePic.image = p1Img
- 我已经在 Storyboard 中为个人资料图片指定了准确的高度和宽度。
- 我尝试以编程方式将 .contentMode 添加为 .ScaleAspectFill,但没有任何效果。
我在这里错过了什么? CGRect?
let originalImageP1 = CIImage(image: p1Img!) let filter = CIFilter(name: "CIPhotoEffectTonal") filter!.setDefaults() filter!.setValue(originalImageP1, forKey: kCIInputImageKey) let outputImage = filter!.outputImage self.p1ProfilePic.image = UIImage(CIImage: outputImage!, scale: UIScreen.mainScreen().scale, orientation: .Up)
使用您的技术从 CIImage
创建 UIImage
会创建不符合 contentMode
的图像。试试这个:
let ciContext = CIContext()
let cgImage = ciContext.createCGImage(filter.outputImage!,
fromRect: filter.outputImage!.extent)
self.p1ProfilePic.image = UIImage(CGImage: cgImage)
干杯!
西蒙