/ Published in: C++
For C#, see http://snipplr.com/view/27706/c-draw-sine-wave-on-bitmap-and-save-to-a-file/
Most examples seem to include a DC but I needed simple code to store MICR data to a BMP file.
Most examples seem to include a DC but I needed simple code to store MICR data to a BMP file.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#define _USE_MATH_DEFINES // needed only for M_PI #include "math.h" // needed only for sin() // Standard MFC includes define CImage, CMitmap and Gdiplus . . . LPCSTR filename = "c:\\testBmp.bmp"; int width = 640; int height = 480; CBitmap bitmap; bitmap.CreateBitmap(width, height, 1, 1, NULL ); // 1,1 means 1 mono-chrome layer. CImage image; image.Attach(bitmap); // For each word in array, set a pixel. In this case, draw a sine wave for ( int i=0; i<width; i++ ) { int y = (int)((sin((double)i*2.0*M_PI/width )+1.0)*(height-1)/2.0); image.SetPixel( i, y, RGB( 0xFF, 0xFF, 0xFF ) ); } image.Save( filename, Gdiplus::ImageFormatBMP);