带有CIAffineClamp过滤器的MacOS和Swift 3 [英] MacOS and Swift 3 with CIAffineClamp filter

查看:144
本文介绍了带有CIAffineClamp过滤器的MacOS和Swift 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用CIAffineClamp来扩展图像并防止高斯模糊使图像边缘模糊.我在Swift 2中使用以下代码:

I need to use CIAffineClamp in order to extend the image and prevent Gaussian Blur from blurring out edges of the image. I have the following code working in Swift 2:

let transform = CGAffineTransformIdentity
let clampFilter = CIFilter(name: "CIAffineClamp")
clampFilter.setValue(inputImage, forKey: "inputImage")
clampFilter.setValue(NSValue(CGAffineTransform: transform), forKey: "inputTransform")

在Swift 3中,CGAffineTransformIdentity重命名为CGAffineTransform.identity.我的代码可以编译,但是在控制台中收到以下错误消息:

In Swift 3 CGAffineTransformIdentity was renamed to CGAffineTransform.identity. My code compiles however I get the following error message in the console:

[CIAffineClamp inputTransfom] is not a valid object.

Apple网站上的文档指出,MacOS上的inputTransform参数采用属性类型为CIAttributeTypeTransformNSAffineTransform对象.,但是我不确定如何使用它.

Documentation on Apple's websites states that inputTransform parameter on MacOS takes an NSAffineTransform object whose attribute type is CIAttributeTypeTransform. but I'm unsure how to use it.

任何帮助将不胜感激.

推荐答案

似乎NSAffineTransform有一个初始化器NSAffineTransform.init(transform:),它使用AffineTransform.

Seems NSAffineTransform has an initializer NSAffineTransform.init(transform:) which takes AffineTransform.

请尝试以下操作:

let transform = AffineTransform.identity
let clampFilter = CIFilter(name: "CIAffineClamp")!
clampFilter.setValue(inputImage, forKey: "inputImage")
clampFilter.setValue(NSAffineTransform(transform: transform), forKey: "inputTransform")

或者最后一行可以是:

clampFilter.setValue(transform, forKey: "inputTransform")

NSAffineTransform

重要

基金会框架的Swift叠加层提供了 AffineTransform结构,它桥接到NSAffineTransform 班级. AffineTransform值类型提供与以下功能相同的功能 NSAffineTransform引用类型,并且两个都可以使用 在与Objective-C API交互的Swift代码中可互换使用. 此行为类似于Swift桥接标准字符串的方式, 数字和相应的基础的集合类型 课.

Important

The Swift overlay to the Foundation framework provides the AffineTransform structure, which bridges to the NSAffineTransform class. The AffineTransform value type offers the same functionality as the NSAffineTransform reference type, and the two can be used interchangeably in Swift code that interacts with Objective-C APIs. This behavior is similar to how Swift bridges standard string, numeric, and collection types to their corresponding Foundation classes.

这篇关于带有CIAffineClamp过滤器的MacOS和Swift 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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