[英]CIFilter has changed UIImage Aspect Ratio - SWIFT
我在我的iOS應用程序中實現了一個CIFilter來profileImages。 我已添加方向以防止像素化但我正在遭受未應用於圖像的寬高比 “ScaleAspectFill”。 相同的彩色圖像具有完美的寬高比......即當我只有:
self.p1ProfilePic.image = p1Img
我在這里錯過了什么? 的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)
干杯!
西蒙
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.