title: How to set bit depth in Magick.NET Read
body: <p>How can I specify the bit depth for the MagickImage.Read() function when reading binary files?</p>
  
  <p>I have a 1024x1024 image represented by 8-bit grayscale values (total file length = 1024x1024 = 1048576 bytes). Using ImageMagick v.7.0.8-7 Q16 x64, I can convert the file using</p>
  
  <pre><code>magick.exe -depth 8 -size 1024x1024 -format Gray Gray:filepath.bin convertedfile.png
  </code></pre>
  
  <p>When I try to convert the file using Magick.NET Q16-AnyCPU v7.5.0.1, </p>
  
  <pre class="lang-cs prettyprint-override"><code>public MagickImage ReadNewMagickImageFromBinary(string fileName){
      MagickReadSettings settings = new MagickReadSettings();
  
      settings.Width = 1024;
      settings.Height = 1024; //if I use settings.Height = 512; , I'm OK.
      settings.Format = MagickFormat.Gray;
      //settings.Depth = 8;                                   //didn't work
      //settings.SetDefine(MagickFormat.Gray, "depth", "8");  //also didn't work
  
      MagickImage newImage = new MagickImage();
      newImage.Depth = 8; //this appears to be ignored once the Read function is called
      newImage.Read(fileName, settings);
  
      return newImage;
  }
  </code></pre>
  
  <p>I get the error</p>
  
  <blockquote>
    <p>Message: ImageMagick.MagickCorruptImageErrorException : unexpected
    end-of-file '': No such file or directory @
    error/gray.c/ReadGRAYImage/241</p>
  </blockquote>
  
  <p>Indicating that the program has read past the end of the file. I've confirmed that Magick.NET is reverting to a 16-bit depth instead of the 8-bit depth I want. I can read the file using <code>settings.Height = 512</code> instead of 1024, which gives me a squashed version of my grayscale image.</p>
  
  <p>I learned from <a href="https://stackoverflow.com/q/34737302/">Memory consumption in Magick.NET</a> that Magick.NET Q16 stores pixels in memory with 16-bit precision; I'm fine with that but it doesn't seem that should preclude 8-bit reading capabilities.</p>
  
  <p>How do I force Magick.NET Q16 to read pixels in with an 8-bit depth?</p>