1using System.Drawing.Imaging;
2using System.Runtime.InteropServices;
6 public partial class ImageView
8 private static void MaskRgbComponents(System.Drawing.Bitmap image,
bool[] enabled)
10 if (enabled.All(value => value))
return;
11 var data = image.LockBits(
new System.Drawing.Rectangle(0, 0, image.Width, image.Height),
12 ImageLockMode.ReadWrite,
PixelFormat.Format32bppArgb);
15 var row =
new byte[image.Width * 4];
16 for (
int y = 0; y < image.Height; y++)
18 IntPtr address = IntPtr.Add(data.Scan0, y * data.Stride);
19 Marshal.Copy(address, row, 0, row.Length);
20 for (
int x = 0; x < row.Length; x += 4)
22 if (!enabled[0]) row[x + 2] = 0;
23 if (!enabled[1]) row[x + 1] = 0;
24 if (!enabled[2]) row[x] = 0;
26 Marshal.Copy(row, 0, address, row.Length);
29 finally { image.UnlockBits(data); }
OpenTK.Graphics.OpenGL.PixelFormat PixelFormat