Members may post updates or alternatives to this current article in order to show different
approaches or add new features.
I'm afraid there are better ways doing this, based on the power of the framework; in this case ColorMatrix is the tool to use. See e.g. here[^] (warning: make sure to use correct matrix elements, corresponding to the coefficients mentioned in the tip/trick).:)
You shouldn't rely on methods from the .NET classes (Bitmap::SetPixel, Bitmap::GetPixel, Color::FromArgb) in the inner loop as these are called intensively, million times per image, and their implementation are opaque to you.If their implementation is opaque to the compiler too, no code...
I would use the colormatrix for that... Look here under the grayscale methodhttp://pawjershauge.blogspot.com/2010/09/imagedrawing-extensions.html
A piece of warning, though: the LockBits method is not a transparent one, it does image format conversion before returning a pointer to the bitmap (this is why it has a PixelFormat argument). And conversely, the UnlockBits method converts back to the original format. My best guess is that when...