Bitmap bmp = new Bitmap(2048, 2048, PixelFormat.Format16bppGrayScale);
GDI + exceptions are rather poor; you have little hope of diagnosing two errors. Smaller is your Save () call, it does not indicate the ImageFormat you want to save. The default is PNG, not BMP, as you hoped.
But the main one is PixelFormat.Format16bppGrayScale. When GDI + was developed, well before .NET, everyone still used CRT instead of LCD monitors. CRTs displayed a good gamut of colors. Despite the fact that there is still no empirical CRT that could display 65,536 different shades of gray. Most limited to the DAC in the video adapter, a chip that converts the value of a digital pixel into an analog signal for a CRT. A DAC that can convert with 16-bit precision at a frequency of 100 MHz or more is not yet technologically feasible. Microsoft gambled with display technology to make this possible someday so that the Format16bppGrayScale format was like a pixel format that might someday be available.
This did not happen. On the contrary, LCDs are much worse in color resolution. Typical LCD panels can only allow 6 bits of color, rather than 8 bits available from the pixel format. Achieving 16-bit color resolution will require a significant technological breakthrough.
Therefore, they were wrong, and since the pixel format is not useful, GDI + does not actually have an image encoder that can write a 16-pixel grayscale image format. Kaboom, when you try to save it to disk, regardless of which ImageFormat you choose.
16bpp shades of gray are actually used, the radiological image uses this pixel format. With a very expensive display to make it really useful. However, such equipment invariably uses a custom image format for this; DICOM is the usual choice. GDI + does not have a codec for it.
You will need to shop for a library that supports the image format your client wants. Lead Tools are thousands of gorillas in this product segment.
Hans passant
source share