C ++ reads and stores a BMP Image
C ++ source code:
# Include
# Include
# Include
# Include
# Include
# Include
Using namespace std; void main () {char fileName [30]; // defines the name of the opened image char * buf; // defines the file to read the buffer char * p; int r, g, b, pix; HWND wnd; // window handle HDC dc; // drawing device environment handle FILE * fp; // define FILE pointer FILE * fpw; // define the storage file pointer DWORD w, h; // define the length and width of the read image DWORD bitCorlorUsed; // define the DWORD bitSize; // define the image size BITMAPFILEHEADER bf; // Image File Header BITMAPINFOHEADER bi; // image file header information cout <enter the name of the file to be opened:; cin> fileName; if (fp = fopen (fileName, rb) = NULL) {cout <file not found !; Exit (0);} fread (& bf, sizeof (BITMAPFILEHEADER), 1, fp); // read the BMP file header file fread (& bi, sizeof (BITMAPINFOHEADER), 1, fp); // read the header file information of the BMP file w = bi. biWidth; // obtain the image width h = bi. biHeight; // obtain the image's high bitSize = bi. biSizeImage; // obtain the image's sizebuf = (char *) malloc (w * h * 3); // allocate the buffer size fseek (fp, long (sizeof (BITMAPFILEHEADER) + sizeof (BITMAPINFOHEADER), 0); // locate the starting position of the pixel fread (buf, 1, w * h * 3, fp ); // start to read data wnd = GetForegroundWindow (); // obtain the window handle dc = GetDC (wnd); // obtain the drawing device int x = 40; int y = 40; p = buf; for (int j = 0; j
Input File Name:
Show image:
Stored files: