title: How to use a slider control to adjust the brightness of a Bitmap?
body: <p>I'm trying to adjust the RGB values to essentially darken or lighten a picture in my image processor project. It would be nice to incorporate both darken and lighten on one TrackBar control, with the neutral, unchanged image being when the slider is set to 0 in the middle.<br>
  However, I'm currently still trying to figure out how to do just one feature, for example, darkening, on one TrackBar.</p>
  
  <p>After putting a TrackBar control (<code>Min 0, Max 10</code>) in my project I use the <code>trackbar_scroll</code> event to detect when the TrackBar is scrolled.<br>
  I've also coded it to darken the image by subtracting a certain byte value from RGB of each pixel of the image.<br>
  The scrollbar successfully darkens the image when you slide it right, however I want to also un-darken it when you slide the TrackBar to the left back to its original position.</p>
  
  <pre><code>private void trbBrightness_Scroll(object sender, EventArgs e)
  {
      if (bitmapImage == null) return; 
  
      Byte Red, Green, Blue;
      int iWidth = 320;
      int iHeight = 240;
  
      for (int i = 0; i &lt; iWidth; i++)
      {
          for (int j = 0; j &lt; iHeight; j++)
          {
              Color pixel = ImageArray[i, j];
  
              Red = pixel.R;
              Green = pixel.G;
              Blue = pixel.B;
  
              Color newColor = 
                  Color.FromArgb(255, 
                                 Red - Convert.ToByte(Red * (trbBrightness.Value * 0.1)), 
                                 Green - Convert.ToByte(Green * (trbBrightness.Value * 0.1)), 
                                 Blue - Convert.ToByte(Blue * (trbBrightness.Value * 0.1)));
              ImageArray[i, j] = newColor;
  </code></pre>
  
  <p>Right now it just darkens the image like I want it to, however I expect, when slid left, the slider to basically undo the darkening when you slid it right.</p>
  
  <p>Is there a way to detect when the value of the slider is increasing, do this, and when the slider value is decreasing, do this?<br>
  I'm assuming I'd have to somehow store the old trackbar value so I can compare it with the new one?</p>
  
  <hr>
  
  <p>where can I get:   </p>
  
  <pre><code>if (trackbar value is increasing) 
  {
  
  } 
  else if (trackbar value is decreasing)
  {
  
  }
  </code></pre>