带有CIAffineClamp过滤器的MacOS和Swift 3 [英] MacOS and Swift 3 with CIAffineClamp filter
问题描述
我需要使用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
参数采用属性类型为CIAttributeTypeTransform
的NSAffineTransform
对象.,但是我不确定如何使用它.
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")
重要
基金会框架的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 theNSAffineTransform
class. TheAffineTransform
value type offers the same functionality as theNSAffineTransform
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屋!