title: Increase/decrease brightness of image using UISlider?
body: <p>I am building an iOS app which is based on image operations. </p>
  
  <p>I want to increase and decrease brightness of image by slider value. </p>
  
  <p>I have used this code to do this:</p>
  
  <pre><code>@IBOutlet var imageView: UIImageView!
  @IBOutlet var uiSlider : UISlider!
  override func viewDidLoad() 
     {
          super.viewDidLoad()
          var image = UIImage(named: "54715869.jpg")
          imageView.image = image
          uiSlider.minimumValue = -0.2
          uiSlider.maximumValue = 0.2
          uiSlider.value = 0.0
          uiSlider.maximumTrackTintColor = UIColor(red: 0.1, green: 0.7, blue: 0, alpha: 1)
          uiSlider.minimumTrackTintColor = UIColor.blackColor()
          uiSlider.addTarget(self, action: "brightnesssliderMove:", forControlEvents: UIControlEvents.TouchUpInside)
          uiSlider.addTarget(self, action: "brightnesssliderMove:", forControlEvents: UIControlEvents.TouchUpOutside)
      }
      func brightnesssliderMove(sender: UISlider)
      {
          var filter = CIFilter(name: "CIColorControls");
          filter.setValue(NSNumber(float: sender.value), forKey: "inputBrightness")
          var image = self.imageView.image
          var rawimgData = CIImage(image: image)
          filter.setValue(rawimgData, forKey: "inputImage")
          var outpuImage = filter.valueForKey("outputImage")
          imageView.image = UIImage(CIImage: outpuImage as CIImage)
  
      }
  </code></pre>
  
  <p>Now my question is that when I increase slider value it also increase brightness of image but only when I change slider position for first time. </p>
  
  <p>When I am again changing the position of slider I am getting this errror: </p>
  
  <blockquote>
    <p>fatal error: unexpectedly found nil while unwrapping an Optional value.</p>
  </blockquote>
  
  <p>This error is coming at line: </p>
  
  <pre><code>imageView.image = UIImage(CIImage: outpuImage as CIImage)
  </code></pre>
  
  <p>This time <code>rawimgData</code> data comes nil.</p>