How do i draw this more efficiently?
I can feel the lag when i call the code below. NOTE this is about pixel editing and not clearing the screen.
int colorIndex = 0;
private void pictureBox1_Click(object sender, EventArgs e)
{
if (colorIndex == 0)
draw(Color.DimGray);
else if(colorIndex ==1)
draw(Color.ForestGreen);
colorIndex++;
colorIndex = colorIndex % 2;
pictureBox1.Invalidate();
//pictureBox1.Update();
}
void draw(Color c)
{
//var bdata = b.LockBits(Rectangle.Empty, System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
//var px = bdata.Scan0;
var px = b;
{
for (int y = 0; y < b.Height; y++)
{
for (int x = 0; x < b.Width; x++)
//px[y * b.Width + x] = -1;
px.SetPixel(x, y, c);
}
}
//b.UnlockBits(bdata);
}