title: Convert 8 bit persample to 1 bit per sample image
body: <p>I have 8 bit per sample image grayscale. I want to convert it using Libtiff.net:</p>
  
  <pre><code> using (Tiff input = Tiff.Open(fileIn, "r"))
              {
                  using (Tiff output = Tiff.Open(fileOut, "w"))
                  {
                      for (short page = 0; page &lt; input.NumberOfDirectories(); page++)
                      {
                          input.SetDirectory(page);
                          output.SetDirectory(page);
  
                          if (input.GetField(TiffTag.COMPRESSION)[0].ToInt() == (int)Compression.LZW)
                          {
                              int width = input.GetField(TiffTag.IMAGEWIDTH)[0].ToInt();
                              int height = input.GetField(TiffTag.IMAGELENGTH)[0].ToInt();
                              int xres = input.GetField(TiffTag.XRESOLUTION)[0].ToInt();
                              int yres = input.GetField(TiffTag.YRESOLUTION)[0].ToInt();
  
                              int samplesPerPixel = input.GetField(TiffTag.SAMPLESPERPIXEL)[0].ToInt();
                              int bitsPerSample = input.GetField(TiffTag.BITSPERSAMPLE)[0].ToInt();
                              int photo = input.GetField(TiffTag.PHOTOMETRIC)[0].ToInt();
  
                              int scanlineSize = input.ScanlineSize();
  
                              byte[][] buffer = new byte[height][];
  
  
                              for (int i = 0; i &lt; height; ++i){
                                  buffer[i] = new byte[scanlineSize];
                                  input.ReadScanline(buffer[i], i);    
                              }
  
                              output.SetField(TiffTag.IMAGEWIDTH, width);
                              output.SetField(TiffTag.IMAGELENGTH, height);
                              output.SetField(TiffTag.COMPRESSION, Compression.CCITTFAX4);
                              output.SetField(TiffTag.PHOTOMETRIC, Photometric.MINISBLACK);
                              output.SetField(TiffTag.SAMPLESPERPIXEL, 1);
                              output.SetField(TiffTag.BITSPERSAMPLE, 1);
                              output.SetField(TiffTag.XRESOLUTION, xres);
                              output.SetField(TiffTag.YRESOLUTION, yres);
  
                              for (int i = 0; i &lt; height; ++i)
                                  output.WriteScanline(buffer[i], i);
  
                              output.WriteDirectory();
  
                          }
                      }
                  }
  
              }
  </code></pre>
  
  <p>How can i get 8 bit array to 1 bit array image?
  I want to do it without converting byte array to bitmap object.
  What is the right way?
  Thanks</p>