2

I have the following block of code that utilizes the GPUImage2 library to filter video in real time. The idea is to be able to cycle these filters based on button clicks. But only one filter will be applied and whenever I try and cycle to the next filter it does not change. Here is my function:

func filterToggle() {
    switch(filterSelected) {
    case 0:
        let sketch = SketchFilter()
        camera! --> sketch --> renderView
        break;
    case 1:
        let toon = ToonFilter()
        camera! --> toon --> renderView
        break;
    default:
        break;
    }
    camera?.startCapture()
}

Thank you for any help!

thepyramid
  • 59
  • 6

1 Answers1

2

You have to disconnect the previous filters from the renderView and the camera before switching to another.

Before adding new filters to the chain, call removeAllTargets() on the camera and the previous filter (you may want to have an instance variable that stores the previous filter in order to do this). The Mac version of FilterShowcase demonstrates this in action.

Brad Larson
  • 168,330
  • 45
  • 388
  • 563