CIFilter已更改UIImage Aspect Ratio - SWIFT [英] CIFilter has changed UIImage Aspect Ratio - SWIFT
问题描述
我已经实现了一个CIFilter到我的iOS应用程序profileImages。我添加了方向以防止像素化,但我受困于宽高比ScaleAspectFill不适用于图像。相同的彩色图像具有完美的纵横比...当我只有:
I have implemented a CIFilter to profileImages in my iOS app. I have added orientation to prevent pixelation but I am suffering from the aspect ratio "ScaleAspectFill" not being applied to the images. The same images in colour have the perfect aspect ratio...i.e. when I just have:
self.p1ProfilePic.image = p1Img
- 我已为故事板中的个人资料图片指定了确切的高度和宽度。
- 以编程方式添加.contentMode作为.ScaleAspectFill,但没有任何效果。
-
我在这里缺少什么? CIGhototer(name:CIPhotoEffectTonal); CGRect?
- I have specified exact height and widths for the profile images in Storyboard.
- I have tried adding programmatically the .contentMode as .ScaleAspectFill but with no effect whatsoever.
What am I missing here? 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 $ c $创建
UIImage
c>使用您的技术创建不尊重 contentMode
的图像。尝试这样:
Creating a UIImage
from a CIImage
with your technique creates images that don't respect contentMode
. Try this instead:
let ciContext = CIContext()
let cgImage = ciContext.createCGImage(filter.outputImage!,
fromRect: filter.outputImage!.extent)
self.p1ProfilePic.image = UIImage(CGImage: cgImage)
干杯!
Simon
这篇关于CIFilter已更改UIImage Aspect Ratio - SWIFT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!