C#, draw sine wave on Bitmap and save to a file


/ Published in: C#
Save to your folder(s)

For MFC, see: http://snipplr.com/view/24917/mfc-cimage-cmitmap-draw-a-sine-wave-and-save-to-a-bmp-file/


Copy this code and paste it in your HTML
  1. string filename = @"C:\0\test.bmp";
  2. int width = 640;
  3. int height = 480;
  4. Bitmap b = new Bitmap(width, height);
  5.  
  6. for (int i = 0; i < width; i++)
  7. {
  8. int y = (int)((Math.Sin((double)i*2.0*Math.PI/width )+1.0)*(height-1)/2.0);
  9. b.SetPixel(i, y, Color.Black);
  10. }
  11. b.Save(filename);

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.