【问题标题】:Convolutional CIFilter in SwiftSwift 中的卷积 CIFilter
【发布时间】:2016-12-13 17:46:06
【问题描述】:

我的卷积过滤器不适用于我在屏幕上显示的实时视频预览。将过滤器更改为 Sepia 过滤器显示正确,但将其更改为 CIConvolution3X3 失败。

let weights:[CGFloat] = [1, 0, -1, 2, 0, -2, 1, 0, -1]
result = (CIFilter(name: "CIConvolution3X3", withInputParameters: [
    kCIInputImageKey: result,
    kCIInputWeightsKey: CIVector(values: weights, count: 9),
    kCIInputBiasKey: NSNumber(float: 0.5)
])?.outputImage)!

【问题讨论】:

  • 我也有同样的问题。我想问题是偏差键,因为没有偏差它对我有用。你已经想通了吗?
  • 运气好能确定为什么我们不能使用 inputBias 作为参数吗?文档 (developer.apple.com/library/archive/documentation/…) 明确指定 inputBias 应作为 CIAttributeTypeDistance 类型的属性传递。我猜它是自动设置的,但我希望它有助于找到解决方案。

标签: ios swift cifilter


【解决方案1】:

我遇到了同样的问题!略有不同的上下文,我试图将使用CIConvolution3X3 过滤的结果CIImage 转换为UIImage。这在运行时失败并显示与上述相同的症状。 (将 inputBias 键设置为 0 以外的任何值都会导致崩溃)失败的确切行是 self.imageView.image = UIImage(ciImage: ciImage)

我确实找到了解决方案。关键是使用CIContext转换图像:

let context = CIContext(options: nil)
guard let cgImage = context.createCGImage(ciImage, from: rectangle) else { return }
let uiImage = UIImage(cgImage: cgImage)

希望这会有所帮助?

【讨论】:

    猜你喜欢
    • 2020-10-02
    • 1970-01-01
    • 1970-01-01
    • 2015-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-11
    • 2021-11-09
    相关资源
    最近更新 更多