Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>None of the examples above create 8-bit (8bpp) bitmap images. Some software, such as image processing, only supports 8bpp. Unfortunately the MS .NET libraries do not have a solution. The <a href="http://msdn.microsoft.com/en-us/library/system.drawing.imaging.pixelformat.aspx" rel="nofollow noreferrer">PixelFormat.Format8bppIndexed</a> format looks promising but after a lot of attempts I couldn't get it working. </p> <p>To create a true 8-bit bitmap file you need to create the <a href="http://en.wikipedia.org/wiki/BMP_file_format" rel="nofollow noreferrer">proper headers</a>. Ultimately I found the <a href="http://www.codeproject.com/KB/recipes/GrayScale.aspx" rel="nofollow noreferrer">Grayscale library</a> solution for creating 8-bit bitmap (BMP) files. The code is very simple:</p> <pre><code>Image image = Image.FromFile("c:/path/to/image.jpg"); GrayBMP_File.CreateGrayBitmapFile(image, "c:/path/to/8bpp/image.bmp"); </code></pre> <p>The code for this project is far from pretty but it works, with one little simple-to-fix problem. The author hard-coded the image resolution to 10x10. Image processing programs do not like this. The fix is open GrayBMP_File.cs (yeah, funky file naming, I know) and replace lines 50 and 51 with the code below. The example sets the resolution to 200x200 but you should change it to the proper number. </p> <pre><code>int resX = 200; int resY = 200; // horizontal resolution Copy_to_Index(DIB_header, BitConverter.GetBytes(resX * 100), 24); // vertical resolution Copy_to_Index(DIB_header, BitConverter.GetBytes(resY * 100), 28); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload