I’m working on a bit-based B/W/Greyscale Pre-Compiled font format, and was having issues with either reading or writing the format, (I’ve not been able to determine where the issue was. (I do have a B/W bit-based version working, but an Aliased font doesn’t look too good, as you can imagine, especially when working with a 320×200 pixel screen) ) but decided that just using a BinaryWriter would be much easier than writing to a bool[] when I pulled the image data.
The basic format of a pixel in the file looks like this:
1 – White Pixel (Shortest, as this would be most of the pixels)
00 – Black Pixel (No reason to write 10-bits for a pure black pixel, which there are a reasonable number of)
01 – Greyscale Pixel, and is followed by 1 byte describing the shade of the pixel
Now, everything is fine and dandy with writing the required info, as that’s all full bytes, but the default .Net 4.0 BinaryWriter writes a Boolean value as a full byte, and as you can imagine, that negates the use of a bit-based format. So I was wondering, is there a BinaryWriter, (and BinaryReader) implementation out there that’s bit-based
Edit:
I ended up creating my own. (See the answer for the code.)
I ended up writing my own, so here they are.
The BinaryWriter (I’ve only overridden the ones that I needed)
And, the BinaryReader, once again, I’ve only overridden the methods that I needed.