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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#pragma pack(push, 1)
typedef unsigned char uc;
typedef unsigned int ui;
typedef unsigned short us;
typedef struct
{
uc r;
uc g;
uc b;
uc reserved;
}Color;
typedef struct
{
uc signature[2];
ui leng;
ui reserved;
ui offset;
ui taille;
ui largeur;
ui hauteur;
us nplans;
us nbits;
ui compression;
ui taille_img;
ui Hres;
ui Vres;
ui ncolor;
ui nimportantcolor;
Color palette;
}BMP;
void ShowTypes(void)
{
printf("int=%d Octes\n",sizeof(int));
printf("unsigned int=%d Octes\n",sizeof(unsigned int));
printf("char=%d Octes\n",sizeof(char));
printf("unsigned char=%d Octes\n",sizeof(unsigned char));
printf("short=%d Octes\n",sizeof(short));
printf("unsigned short=%d Octes\n",sizeof(unsigned short));
printf("long=%d Octes\n",sizeof(long));
printf("unsigned long=%d Octes\n",sizeof(unsigned long));
system("pause");
}
void ShowBMPInfo(BMP img)
{
printf("Entete du fichier\n");
printf("------------------\n");
printf("Signature du fichier: %c%c\n"\
"Taille du fichier: %d Ko\n"\
"Champ reserve: %d\n"\
"Offset: %d\n\n",img.signature[0],img.signature[1],img.leng/1000,img.reserved,img.offset);
printf("Entete de l'image\n");
printf("------------------\n");
printf("Largeur: %d\n"\
"Hauteur: %d\n"\
"Nombre de plans: %d\n"\
"Nombre de bits: %d Bits\n"\
"Type de compression: %d\n"\
"Taille de l'image: %d Ko\n"\
"Resolution Horizontale: %d\n"\
"Resolution Verticale: %d\n"\
"Nombre de couleur: %d\n"\
"Nombre de couleurs importante: %d\n\n",img.largeur,img.hauteur,img.nplans,img.nbits,img.compression,img.taille_img/1000,img.Hres
,img.Vres,img.ncolor,img.nimportantcolor);
printf("Entete de la palette\n");
printf("------------------\n");
printf("couleur R: %d\n"\
"couleur G: %d\n"\
"couleur B: %d\n"\
"reserved: %d\n\n",img.palette.r,img.palette.g,img.palette.b,img.palette.reserved);
}
int main(int argc,char** argv)
{
FILE* fichier=NULL;
FILE *f=NULL;
ui i,j;
BMP img;
BMP *imgcpy=malloc(sizeof(BMP));;
uc data[640][428]={{0}};
fichier=fopen("image.bmp","rb");
f=fopen("imagecpy.bmp","wb");
if (fichier!=NULL)
{
fread(&img,sizeof(img),1,fichier);/*on lit les infos sur l'image*/
memcpy(imgcpy,&img,sizeof(BMP));
fread(data,sizeof(data),1,f);
if (img.signature[0]=='B' && img.signature[1]=='M')
{
ShowBMPInfo(img);
fwrite(imgcpy,sizeof(BMP),1,f); /* on enregistre les infos du header*/
fwrite(data,sizeof(data),1,f);/* on enregistre les données iamges*/
}
else
{
printf("ce fichier n'est pas un fichier bmp\n");
}
}
else printf("impossible d'ouvrir le fichier");
getchar();
fclose(fichier);
fclose(f);
(void)argc;
(void)argv;
return 0;
} |
Partager