I have a grayscale image coming from a camera and I need to display it on a form However, C# is only able to convert 8bit grayscale images to 8BPP indexed image with 1:1 color palette, there is no Grayscale format in C# Bitmap
And when I try to draw a line using this:
using (var graphics = Graphics.FromImage(outputBitmap))
{
Pen blackPen = new Pen(Color.Black, 3);
graphics.DrawLine(blackPen, outputBitmap.Width/2, 0, outputBitmap.Width / 2, outputBitmap.Height-1);
}
I get an error that
"A Graphics object cannot be created from an image that has an indexed pixel format."
So what do I do? I don't want to change the format or duplicate the image by copying pixels in memory.
I also cannot set pixels directly in 8BPP images
Is this really a limitation of C# and windows forms? That you cannot edit grayscale images?
Every API like OpenCV is able to edit 8 bit images without issues.