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
|
#include <stdio.h>
#include <stdlib.h>
typedef struct bmpheader
{
unsigned short type;
unsigned long file_size;
unsigned long reserved;
unsigned long data_offset;
unsigned long header_size;
signed long width;
signed long height;
unsigned short planes;
unsigned short bits_per_pixel;
unsigned int compression;
unsigned long data_size;
signed horizontal_resolution;
signed vertical_resolution;
unsigned long colors;
unsigned long important_colors;
}bmpheader;
void readbmpheader(char *bitmapfilename)
{
FILE *bitmapfile;
bmpheader header;
bitmapfile=fopen(bitmapfilename,"rb");
if(bitmapfile==NULL)
{
printf("Error when reading...!\n");
exit(-1);
}
fread(&header,sizeof(bmpheader),1,bitmapfile);
printf("Bitmap type:\n");
printf("%d\n",header.type);
printf("Bitmap size:\n");
printf("%d\n",header.file_size);
printf("Bitmap reserved value:\n");
printf("%d\n",header.reserved);
printf("Bitmap data offset:");
printf("%d\n",header.data_offset);
printf("Bitmap header size:\n");
printf("%d\n",header.header_size);
printf("Bitmap width:\n");
printf("%d\n",header.width);
printf("Bitmap height:\n");
printf("%d\n",header.height);
printf("Bitmap planes number:\n");
printf("%d\n",header.planes);
printf("Bitmap bits per pixel:\n");
printf("%d\n",header.bits_per_pixel);
printf("Bitmap compression mode:\n");
printf("%d\n",header.compression);
printf("Bitmap data size:\n");
printf("%d\n",header.data_size);
printf("Bitmap horisontal resolution:\n");
printf("%d\n",header.horizontal_resolution);
printf("Bitmap vertical resolution:\n");
printf("%d\n",header.vertical_resolution);
printf("Bitmap Colors:\n");
printf("%d\n",header.colors);
printf("Bitmap Important colors:\n");
printf("%d\n",header.important_colors);
}
int main()
{
readbmpheader("\\Image.bmp");
getchar();
return 0;
} |
Partager