Posted By

jimfred on 02/04/10


Tagged


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

maxbaines
danfinrud55


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


 / Published in: C#
 

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

  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  

You need to login to post a comment.