Return to Snippet

Revision: 21629
at December 16, 2009 16:09 by jimfred

Initial Code
#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;

// 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);

Initial URL

Initial Description
For C#, see

Most examples seem to include a DC but I needed simple code to store MICR data to a BMP file.

Initial Title
MFC, CImage, CMitmap, draw a sine wave and save to a BMP file.

Initial Tags

Initial Language