// GDI+ still lies to us - the return format is BGR, NOT RGB. BitmapData bmData = RImage.LockBits(new Rectangle(0, 0, RImage.Width, RImage.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); int stride = bmData.Stride; System.IntPtr Scan0 = bmData.Scan0; unsafe { byte* p = (byte*)(void*)Scan0; int nOffset = stride - RImage.Width * 3; byte red, green, blue; for (int y = 0; y < RImage.Height; ++y) { for (int x = 0; x < RImage.Width; ++x) { blue = p[0]; green = p[1]; red = p[2]; p[0] = p[1] = p[2] = (byte)(.299 * red + .587 * green + .114 * blue); p += 3; } p += nOffset; } } RImage.UnlockBits(bmData);
UnlockBits
Graphics.DrawImage
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)