#include<graphics.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
int SaveBMP16(char []);
typedef unsigned char byte;
typedef unsigned int word;
typedef unsigned long dword;
void main()
{
int gdriver;
int gmode, errorcode;
detectgraph(&gdriver,&gmode);
initgraph(&gdriver, &gmode, "c:\\tc\\bgi");
errorcode = graphresult();
if (errorcode != grOk)
exit(1);
int midx, midy,radius = 100;
midx = getmaxx() / 2;
midy = getmaxy() / 2;
setcolor(getmaxcolor());
circle(midx, midy, radius);
SaveBMP16("Circle.Bmp");
}
struct BMP
{
byte bfType[2];
dword bfSize;
word bfReserved1;
word bfReserved2;
dword bfOffset;
dword biSize;
dword biWidth;
dword biHeight;
word biPlanes;
word biBitCount;
dword biCompression;
dword biSizeImage;
dword biXPelsPerMeter;
dword biYPelsPerMeter;
dword biClrUsed;
dword biClrImportant;
};
int SaveBMP16(char file[])
{
int i=0, j=0, r, g, b;
FILE *fp;
BMP *bmp;
bmp=(BMP *)malloc(54);
bmp->bfType[0]='B';
bmp->bfType[1]='M';
bmp->bfSize=153718;
bmp->bfReserved1=0;
bmp->bfReserved2=0;
bmp->bfOffset=118;
bmp->biSize=40;
bmp->biWidth=640;
bmp->biHeight=480;
bmp->biPlanes=1;
bmp->biBitCount=4;
bmp->biCompression=0;
bmp->biSizeImage=153600;
bmp->biXPelsPerMeter=0;
bmp->biYPelsPerMeter=0;
bmp->biClrUsed=0;
bmp->biClrImportant=0;
fp=fopen(file, "wb");
if(fp == NULL)
{
printf("File can't be open");
getch();
return 1;
}
fwrite(bmp, 54, 1, fp);
fseek(fp, 54L, SEEK_SET);
fputc(0x0, fp);
fputc(0x0, fp);
fputc(0x0, fp);
fputc(0x0, fp);
fputc(127, fp);
fputc(0x0, fp);
fputc(0x0, fp);
fputc(0x0, fp);
fputc(0x0, fp);
fputc(127, fp);
fputc(0x0, fp);
fputc(0x0, fp);
fputc(127, fp);
fputc(127, fp);
fputc(0x0, fp);
fputc(0x0, fp);
fputc(0x0, fp);
fputc(0x0, fp);
fputc(127, fp);
fputc(0x0, fp);
fputc(127, fp);
fputc(0x0, fp);
fputc(127, fp);
fputc(0x0, fp);
fputc(0x0, fp);
fputc(192, fp);
fputc(192, fp);
fputc(0x0, fp);
fputc(192, fp);
fputc(192, fp);
fputc(192, fp);
fputc(0x0, fp);
fputc(128, fp);
fputc(128, fp);
fputc(128, fp);
fputc(0x0, fp);
fputc(255, fp);
fputc(0x0, fp);
fputc(0x0, fp);
fputc(0x0, fp);
fputc(0x0, fp);
fputc(255, fp);
fputc(0x0, fp);
fputc(0x0, fp);
fputc(255, fp);
fputc(255, fp);
fputc(0x0, fp);
fputc(0x0, fp);
fputc(0x0, fp);
fputc(0x0, fp);
fputc(255, fp);
fputc(0x0, fp);
fputc(255, fp);
fputc(0x0, fp);
fputc(255, fp);
fputc(0x0, fp);
fputc(0x0, fp);
fputc(255, fp);
fputc(255, fp);
fputc(0x0, fp);
fputc(255, fp);
fputc(255, fp);
fputc(255, fp);
fputc(0x0, fp);
i=0;
j=479;
fseek(fp, 118, SEEK_SET);
while(j>=0)
{
i=0;
while(i<640)
{
fputc((getpixel(i, j)<<4) | getpixel(i+1, j), fp);
i+=2;
}
j--;
}
free(bmp);
fclose(fp);
return 0;
}