System.Drawing has poor support for 8-bit images. When converting from 24 or 32-bit images to 8-bit; it'll always use a fixed default color palette. That default color palette only contains 16 shades of grey, the other entries are various colors.
Do you have the same problem when saving as '.bmp'? If yes, then the conversion to the 8-bit format already happened earlier, you'll have to figure out where your program does that and fix the issue there.
If it's only the tiff encoder that converts to 8-bit, you'll have to do the 8-bit conversion in a separate step first. Create an 8-bit image, fill Image.Palette
with a gray-scale palette, and then copy the bitmap data over.
But System.Drawing has poor support for 8-bit images, and several methods (e.g. SetPixel
) will just throw InvalidOperationException
when dealing with such images. You will probably have to use unsafe code (with LockBits
etc.) to copy the bitmap data. If I were you, I'd look if there are alternative graphics libraries you could use.