【问题标题】:Swift error in console "CIKernel's ROI function did not allow tiling"控制台中的 Swift 错误“CIKernel 的 ROI 功能不允许平铺”
【发布时间】:2018-07-24 08:42:33
【问题描述】:

完全错误是“无法渲染 921600 像素,因为 CIKernel 的 ROI 函数不允许平铺。”每次我尝试使用翻译转换 ciImage 时。

代码很简单:

    var flippedGradient = gradient.transformed(by:CGAffineTransform(scaleX: -1, y: 1))
    flippedGradient = gradient.transformed(by:CGAffineTransform(translationX: flippedGradient.extent.width, y: 0)) // causes error

    // mask hue 2 with gradient with transparent background
    let alphaMaskBlend2 = CIFilter(name: "CIBlendWithAlphaMask",
                                   withInputParameters: [kCIInputImageKey: hue2,
                                                         kCIInputBackgroundImageKey: transBGCI,
                                                         kCIInputMaskImageKey:flippedGradient])?.outputImage

进行翻译会导致错误并使我整个屏幕变灰,而不是正常渲染图像。

相关线程,没有关于如何翻译我的 ciImage 的解决方案: iOS 10: CIKernel's ROI function did not allow tiling

【问题讨论】:

    标签: swift transform translate ciimage cikernel


    【解决方案1】:

    请原谅我迟到了,但我刚刚遇到了同样的错误,可能有一些帮助。我使用了不同的滤镜 (CIShadedMaterial),并通过将图像缩小到更小的尺寸来解决它。这是我的代码:

    extension UIImage {
        func resizeToBoundingSquare(_ boundingSquareSideLength : CGFloat) -> UIImage {
            let imgScale = self.size.width > self.size.height ? boundingSquareSideLength / self.size.width : boundingSquareSideLength / self.size.height
            let newWidth = self.size.width * imgScale
            let newHeight = self.size.height * imgScale
            let newSize = CGSize(width: newWidth, height: newHeight)
            UIGraphicsBeginImageContext(newSize)
            self.draw(in: CGRect(x: 0, y: 0, width: newWidth, height: newHeight))
            let resizedImage = UIGraphicsGetImageFromCurrentImageContext()
            UIGraphicsEndImageContext();
            return resizedImage!
        }
    

    用法:

    myImage = myImage.resizeToBoundingSquare(640)
    
    • 我最初使用 4096 并意识到我把它留在里面了。
    • 为此,信用确实需要转到Simon Gladman。我找不到确切的地方,我发现使用 640x640 是“足够好”,但这个链接“足够接近”。

    【讨论】:

      猜你喜欢
      • 2017-04-05
      • 2015-11-14
      • 2018-11-13
      • 2020-08-18
      • 2021-04-27
      • 2018-04-25
      • 2012-11-02
      • 2021-08-11
      • 2018-07-12
      相关资源
      最近更新 更多