前にもやったSetPixelを使わずにBitmapの色を変える方法と同じ要領で
private void Form1_Paint(object sender, PaintEventArgs e)
{
byte[] dat = new byte[100 * 100 * 3];
for (int h = 0; h < 100; h++)
{
for (int w = 0; w < 100; w++)
{
// 真っ赤なデータを用意
int index = h * 100 * 3 + w * 3;
dat[index] = 0;
dat[index + 1] = 0;
dat[index + 2] = 255;
}
}
using (Bitmap bmp = new Bitmap(100, 100, PixelFormat.Format24bppRgb))
{
BitmapData bd = bmp.LockBits(
new Rectangle(0, 0, 100, 100),
ImageLockMode.WriteOnly,
PixelFormat.Format24bppRgb);
Marshal.Copy(dat, 0, bd.Scan0, dat.Length);
bmp.UnlockBits(bd);
e.Graphics.DrawImage(bmp, 0, 0);
}
}真っ赤な四角がフォームに表示されます