#include #include #include #include #include struct BMP_HEADER_TYPE { int image_format_type; long image_file_size; int image_reserved1; int image_reserved2; long image_bitmap_offset; long image_header_size; long image_width; long image_height; int image_planes; int image_pixel_per_bit; long image_compress; long image_bitmap_image_size; long image_horizon_resolution; long image_vertical_resolution; long image_used_color; long image_pallette; } BMP_HEADER; struct BMP_PALETTE { unsigned char r, g ,b; } pal[16]; GRAPH_INITIAL() { int graphdriver = DETECT, graphmode; graphdriver = DETECT; detectgraph(&graphdriver,&graphmode); initgraph(&graphdriver, &graphmode,""); } LOAD_BMP_FILE(char *file_name) { long i, j; char ch; int k; FILE *fp; struct palettetype ppal; getpalette(&ppal); if ((fp = fopen(file_name, "rb"))== NULL) { printf("Cannot Open File \"%s\" !!\a",file_name);exit(0); } fread(&BMP_HEADER,sizeof(BMP_HEADER),1,fp); printf("format type : %d %d\n", BMP_HEADER.image_format_type,0x4d42); printf("file size : %ld\n",BMP_HEADER.image_file_size); printf("reserved 1 : %d\n",BMP_HEADER.image_reserved1); printf("reserved 2 : %d\n",BMP_HEADER.image_reserved2); printf("bitmap_offset : %ld\n",BMP_HEADER.image_bitmap_offset); printf("header size : %ld\n",BMP_HEADER.image_header_size); printf("image width : %ld\n",BMP_HEADER.image_width); printf("image height : %ld\n",BMP_HEADER.image_height); printf("image planes : %d\n", BMP_HEADER.image_planes); printf("image pixel per but : %d\n",BMP_HEADER.image_pixel_per_bit); printf("image compress : %ld\n",BMP_HEADER.image_compress); printf("imgage bitmap image size : %ld\n",BMP_HEADER.image_bitmap_image_size); printf("horizon resolution : %ld\n",BMP_HEADER.image_horizon_resolution); printf("vertical Resolution : %ld\n", BMP_HEADER.image_vertical_resolution); printf("use color : %ld\n", BMP_HEADER.image_used_color); printf("image pallette : %ld\n",BMP_HEADER.image_pallette); printf("\n\n\nPress Anykey !!"); getch(); fread(&pal,sizeof(pal),1,fp); for(k=0;k<16;k++) { pal[k].r = pal[k].r>>2; pal[k].g = pal[k].g>>2; pal[k].b = pal[k].b>>2; setrgbpalette(ppal.colors[k], pal[k].b, pal[k].g, pal[k].r); } for(j=BMP_HEADER.image_height-1;j>=0;j--) for(i=0;i> 4) & 15); putpixel(i+1,j,ch & 15); } fclose(fp); } main() { GRAPH_INITIAL(); LOAD_BMP_FILE("d:\\tc20\\source\\tmp1.bmp"); getch(); closegraph(); }