将GPUImage MultipleBlend从OBJ-C转换为Swift

时间:2019-03-05 18:36:41

标签: swift gpuimage

我正在将我的GPUImage应用程序转换为Swift,但是在转换以下内容时遇到了一些麻烦。

GPUImagePicture *lookupImageSource = [[GPUImagePicture alloc] initWithImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Elevate.png" ofType:nil]]];

        [lookupImageSource forceProcessingAtSize:sourceImage.size];

        GPUImageMultiplyBlendFilter * blendFilter = [[GPUImageMultiplyBlendFilter alloc] init];

        GPUImageOpacityFilter *opacityFilter = [[GPUImageOpacityFilter alloc] init];
        opacityFilter.opacity = sliderValue;

        [lookupImageSource addTarget:opacityFilter];

        [stillImageSource addTarget:blendFilter];
        [opacityFilter addTarget:blendFilter];

        [blendFilter useNextFrameForImageCapture];

        [stillImageSource processImage];
        [lookupImageSource processImage];

        finishedImage = [blendFilter imageFromCurrentFramebufferWithOrientation:sourceImage.imageOrientation];

目前我已转换为以下内容,但运行代码时出现错误。

let filterOpacity = OpacityAdjustment()
            filterOpacity.opacity = 1

            let filterImage = PictureInput.init(image: UIImage.init(named: "Elevate.png")!)
            filterImage.addTarget(filterOpacity)


            let filterMultiplyBlend = MultiplyBlend()
            filterMultiplyBlend.addTarget(filterOpacity)


            imageOutput = sourceImage!.filterWithPipeline{input, output in
                input --> filterMultiplyBlend --> output
            }

我收到此错误作为输出。

  

警告:试图将目标添加到目标的输入容量之外->   Pipeline.swift:addTarget(_:atTargetIndex :):43

1 个答案:

答案 0 :(得分:0)

尝试

        let filterOpacity = OpacityAdjustment()
        filterOpacity.opacity = 1

        let filterImage = PictureInput.init(image: UIImage.init(named: "Elevate.png")!)

        let filterMultiplyBlend = MultiplyBlend()

        imageOutput = sourceImage!.filterWithPipeline{input, output in
            input --> filterOpacity --> filterMultiplyBlend --> output
        }