1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
#include <stdio.h>
#include "windows.h"
int main()
{
int i;
FILE* Pic1 = fopen("pic1.bmp", "rb");
FILE* Pic2 = fopen("pic2.bmp", "rb+");
unsigned char infoPic1[54];
fread(infoPic1, sizeof(unsigned char), 54, Pic1); // read the 54-byte header from Pic1
// extract image height and width from Pic1
int widthPic1 = *(int*)&infoPic1[18];
int heightPic1 = *(int*)&infoPic1[22];
int sizePic1 = 3 * widthPic1 * heightPic1;
unsigned char infoPic2[54];
fread(infoPic2, sizeof(unsigned char), 54, Pic2); // read the 54-byte header from Pic2
// extract image height and width from Pic2
int widthPic2 = *(int*)&infoPic2[18];
int heightPic2 = *(int*)&infoPic2[22];
int sizePic2 = 3 * widthPic2 * heightPic2;
printf("Pic1 is %i*%i pixels and %ibyte\nPic2 is %i*%i and %ibytes\n\n", heightPic1, widthPic1, sizePic1, heightPic2, widthPic2, sizePic2);
system("PAUSE");
return 0;
}
|