2017-06-05 61 views
0

我遵循GPUImage2例子中改變視頻攝像機上濾鏡亮度的示例,我試圖用iOS滑塊控件更改靜態圖像上的濾鏡亮度,但它並沒有改變強度。通過在gpuimage2中的滑塊控件將亮度從0改變到100的過濾器亮度swift

@IBOutlet weak var renderView: RenderView! 
    var filterContrast:ContrastAdjustment! 
    @IBOutlet weak var sliderContrast: UISlider! 
    let inputImage = UIImage(named:"WID-small.jpg")! 
    var picture:PictureInput! 

    // setting dynamic observable property. 
    dynamic var filterValue = 3.0 { 

    didSet { 
     filterContrast.contrast = GLfloat(filterValue) 
     picture.processImage() 
    } 
} 

上滑塊更新viewDidLayoutSubviews

picture = PictureInput(image: inputImage) 
    filterContrast = ContrastAdjustment(); 

    picture --> filterContrast --> renderView 
    filterValue = 3; // will call did set property and call processimage from it 

 filterValue = Double(nm); 

有什麼事情不對,這種方法?

感謝

回答

1

您的每一次滑塊值發生變化,你要創建一個新的ContrastAdjustment過濾器實例,並將其連接到的畫面。您的舊過濾器實例仍然存在,並且RenderView將忽略超出第一個輸入的任何輸入。事實上,你應該已經看到了控制檯上的警告,告訴你這個事實,即你將過多的輸入添加到RenderView。

不是每次都創建一個全新的ContrastAdjustment濾鏡,只需將對比濾鏡保存爲實例變量並在滑塊更改時調整其屬性。

+0

嗨,布拉德,感謝您的迴應,嘗試過任何一種方式,但圖像並沒有改變一些調試的強度,我發現當從滑塊更改值時,targetcontainer計數爲零。 但當我再次添加目標時, self.picture - > self.filterContrast - > self.renderView滑塊更新方法 我面臨以下錯誤: 警告:嘗試添加目標超出目標的輸入容量 - > Pipeline.swift:addTarget(_:atTargetIndex :):43 PS:我現在只是更新屬性的對比值。 –

+0

我更新了我的問題,以便更好地解釋您的問題。 –

+0

@MuhammadFaizanKhatri - 刪除'picture - > filterContrast - > renderView'這一行,因爲不需要再次設置處理管道,如果您嘗試這樣做會產生錯誤。你上面的代碼仍然在創建一個新的ContrastAdjustment實例,所以你沒有顯示你當前的代碼。如果您正在訪問作爲實例變量存儲的ContrastAdjustment,並且這是作爲過濾器鏈的一部分添加的ContrastAdjustment實例,則上述內容應該可以工作。查看SimpleImageFilter Mac應用程序的工作原理。 –