Oh! First of all, forget about
GetPixel/SetPixel
and never recall it again. :-) The performance is not acceptable. Instead, use
System.Drawing.Bitmap.LockBits
. You will find a code sample here:
http://msdn.microsoft.com/en-us/library/5ey6h79d.aspx[
^].
You will need two bitmaps as your target bitmap should be of different pixel format on output, such as
System.Drawing.Imaging.System.Drawing.Imaging.Format16bppGrayScale
, see
http://msdn.microsoft.com/en-us/library/system.drawing.imaging.pixelformat.aspx[
^].
If you simply remove saturation from your bit data and save it in the same format, you will waste memory and disk space on color bitmap while not actually using colors.
Now, grayscale. Those good photographers working with computers know that there are many different ways to make good grayscale. Instead of just setting color saturation to zero, they select one channel, run different filters and creatively combine those transformation in order to emphasize one or another part of dynamic range. You can do it, too.
You can use some simplest method though. Look at this article:
http://www.bobpowell.net/grayscale.htm[
^].
For goodness sake, ignore the first code sample using those stupid
GetPixel/SetPixel
methods. Instead, use the method in the section "Alternative Version using the ColorMatrix class". This is probably the fastest way.
—SA