title: Greyscale darkening problem with Bitmap image in C#
body: <p>I'm loading a 8bppIndexed greyscale image into memory and reading the pixel values.  The problem is that the values I am getting from the pixels do not seem to match the actual image, they are always darker.  My image is a simple grey gradient like this:</p>
  
  <p><img src="https://farm3.static.flickr.com/2591/3681486860_85d9189f90_o.jpg" alt="alt text"></p>
  
  <p>The bottom right pixel is returning 191 and the top left 0.  The top left is actually 64 and bottom right is 255.</p>
  
  <p>Here is how I am loading my image:</p>
  
  <pre><code>Bitmap threshImg = new Bitmap(@"C:\grey.bmp");
  </code></pre>
  
  <p>Checking the PixelFormat confirms it is in Format8bppIndexed.  So I read the bottom right pixel and top left like so:</p>
  
  <pre><code>BitmapData data = threshImg.LockBits(new Rectangle(0, 0, rectWidth, rectHeight), ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
  unsafe
  {
      byte* pixel = (byte*)data.Scan0.ToPointer();
      int topVal = (int)(byte)pixel[0];
      int bottomVal = (int)(byte)pixel[((threshImg.Height * threshImg.Width)) - 1];
  }
  threshImg.UnlockBits(data);
  </code></pre>
  
  <p>If I convert the image to 24bppRbg (and adjust the code accordingly) I see the correct colour values in the respective corners.</p>
  
  <p>Anyone know why I'm getting darker values when using an 8bppIndexed image?</p>