CIFilter已更改UIImage Aspect Ratio - SWIFT [英] CIFilter has changed UIImage Aspect Ratio - SWIFT

查看:226
本文介绍了CIFilter已更改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




  1. 我已为故事板中的个人资料图片指定了确切的高度和宽度。

  2. 以编程方式添加.contentMode作为.ScaleAspectFill,但没有任何效果。

  3. 我在这里缺少什么? CIGhototer(name:CIPhotoEffectTonal); CGRect?

  1. I have specified exact height and widths for the profile images in Storyboard.
  2. I have tried adding programmatically the .contentMode as .ScaleAspectFill but with no effect whatsoever.
  3. 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 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆