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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
typedef struct {
long bfSize;
short bfReserved1;
short bfReserved2;
long bfoffBits;
} HEAD;
typedef struct {
long biSize;
long biWidth;
long biHeight;
short biPlanes;
short biBitCount;
long biCompress;
long biSizeImage;
long biXPelsPerMeter;
long biYPelsPerMeter;
long biClrUsed;
long biClrImportant;
} INFO;
int main (void)
{
char received_file[]="C:/KMP_WT/PrintTest.bmp";
char treated_file[]="C:/KMP_WT/PrintTest_treated.bmp";
FILE *rf = fopen(received_file, "rb");
FILE *tf= fopen(treated_file,"w+");
HEAD head;
fseek(rf, 0, SEEK_END);
unsigned long size = ftell(rf);
fseek(rf, 0, SEEK_SET);
unsigned char *bitbuffer;
bitbuffer=(unsigned char*) malloc (sizeof(char)*size);
fread (bitbuffer,1,size,rf);
short bit[8];
int i;
char eureka;
fseek(rf, 2, 0);
fread(&head, 1, sizeof(HEAD), rf);
fseek(rf, 14, 0);
INFO info_rf,info_tf;
fread(&info_rf, 1, sizeof(INFO), rf);
printf("bmpWidth %d\n", info_rf.biWidth);
printf("bmpHeight %d\n", info_rf.biHeight);
printf("biBitCount %d\n", info_rf.biBitCount);
printf("biSizeImage %d\n", info_rf.biSizeImage);
info_tf=info_rf;
info_tf.biHeight=info_rf.biWidth;
info_tf.biWidth=info_rf.biHeight;
printf("bmpWidth %d\n", info_tf.biWidth);
printf("bmpHeight %d\n", info_tf.biHeight);
printf("biBitCount %d\n", info_tf.biBitCount);
printf("biSizeImage %d\n", info_tf.biSizeImage);
fwrite("BM", 1,2,tf);
fwrite(&head,1,sizeof(HEAD),tf);
fwrite(&info_tf,1,sizeof(INFO),tf);
fwrite("",1,8,tf);
for(i=62;i<size;i++)
fprintf(tf, "%c", bitbuffer[i]);
} |
Partager