title: C# TIFF Bit Wise Check
body: <p>I am trying to determine if a 1BPP indexed TIFF image is using a white pixel or black pixel. To check if my code was correct , I made the application draw the same image it proccessed onto a new image. This is when I noticed some problems and I have beem beating my head trying to figure it out.</p>
  
  <p>I am pretty sure it has something to do with my bitwise check!</p>
  
  <p>origninal image</p>
  
  <p><img src="https://i.stack.imgur.com/JrCc1.png" alt="origninal image  A"></p>
  
  <p>Processed Image</p>
  
  <p><img src="https://i.stack.imgur.com/SHtLy.png" alt="enter image description here"></p>
  
  <p>Test project can be downloaded at <a href="http://www.unclickable.net/code/tiffTest.zip" rel="nofollow noreferrer">http://www.unclickable.net/code/tiffTest.zip</a><br>
       unsafe
                  {
                      //flipStartPoint</p>
  
  <pre><code>                int y;
                  for (y = 0; y &lt; tiffSource.Height; y++)
                  {
                      var Column = (byte*)tiffSource.GetScanlinePointer(y);
                      int x;
                      for (x = 0; x &lt; (tiffSource.Width / 8); x++)
                      {
                          int xm = x * 8;
                          byte b = Column[xm];
  
  
                          if (b &gt; 0)
                          {
  
                                  for (int Z = 0; Z &lt; 8; Z++)
                                  {
  
  
                                      if (((b &amp; (128 &gt;&gt; Z)) != 0))
                                      {
                                          if (lowisWhite)
                                          {
                                              image1.SetPixel((xm + Z), y, Color.FromArgb(0, 255, 255,255));
                                          }
  
                                      }
                                      else
                                      {
                                          if (!lowisWhite)
                                          {
  
                                              image1.SetPixel((xm + Z), y, Color.FromArgb(0, 255,255, 255));
                                          }
                                      }
  
                                  }
  
                          }
                          else
                          {
                              if (!lowisWhite)
                              {
                                  for (int Z = 0; Z &lt; 8; Z++)
                                  {
  
  
                                      image1.SetPixel((xm + Z), y, Color.FromArgb(0, 255, 255, 255));
  
                                  }
                              }
                          }
                      }
                  }
              }
  </code></pre>