かわいらしいにゃんこの画像をリソースに登録しておいて、あえて緑色に染めて描画する例。
private void Form1_Paint(object sender, PaintEventArgs e)
{
using (Bitmap bmp = Resources.Cat)
{
BitmapData bd = bmp.LockBits(
new Rectangle(0, 0, bmp.Width, bmp.Height),
ImageLockMode.ReadWrite, bmp.PixelFormat);
Console.WriteLine(bmp.PixelFormat);
IntPtr scan0 = bd.Scan0;
byte[] buff = new byte[bd.Height * bd.Width * 3];
Marshal.Copy(scan0, buff, 0, buff.Length);
for (int y = 0; y < bd.Height; y++)
{
for (int x = 0; x < bd.Width; x++)
{
int index = y * bd.Width * 3 + x * 3;
buff[index] = 0;
buff[index + 1] = 255;
buff[index + 2] = 0;
}
}
Marshal.Copy(buff, 0, scan0, buff.Length);
bmp.UnlockBits(bd);
e.Graphics.DrawImage(bmp, 0, 0, Width, Height);
}
}