Wednesday, July 08, 2009

draw sine wave on Bitmap

string filename = @"C:\0\test.bmp";
int width = 640;

int height = 480;
Bitmap b = new Bitmap(width, height);

for (int i = 0; i < width; i++)
{
int y = (int)((Math.Sin((double)i*2.0*Math.PI/width )+1.0)*(height-1)/2.0);
b.SetPixel(i, y, Color.Black);
}

b.Save(filename);