public unsafe Image GrayscaleA()
{
Bitmap b = new Bitmap(_image);
BitmapData bData = b.LockBits(new Rectangle(0, 0, _image.Width, _image.Height), ImageLockMode.ReadWrite, b.PixelFormat);
byte bitsPerPixel = GetBitsPerPixel(bData.PixelFormat);
int size = bData.Stride * bData.Height;
byte* scan0 = (byte*)bData.Scan0.ToPointer();
int colWidth = bData.Width * bitsPerPixel / 8;
for (int i = 0; i < bData.Height; ++i)
{
for (int j = 0; j < bData.Width; ++j)
{
byte* data = scan0 + i * bData.Stride + j * bitsPerPixel / 8;
byte magnitude = (byte)(1 / 3d * (data[0] + data[1] + data[2]));
data[0] = (byte)magnitude;
data[1] = (byte)magnitude;
data[2] = (byte)magnitude;
}
}
b.UnlockBits(bData);
return b;
}