Home > Back-end >  TurboC2.0 under 16 color display BMP
TurboC2.0 under 16 color display BMP

Time:03-19

# include
# include
# include
# include
# include
# include
# include
Char * buffer;/ar * malloc ();
Char bmp_to_dat (char * BMP, char * dat)
{unsigned char c [8], scan_times, scan_pixs;
Unsigned char workpos;
Int I, j, k, n, nowpos, iw, ih.
Static int color [16]=,4,2,6,1,5,3,7,8,12,10,14,9,13,11,15 {0}; Scanline unsigned char workline [640], [640].
The FILE * fp, * targetfp;
The union
{unsigned char value;
Struct
{unsigned cl: 4;
Unsigned ch: 4;
} color;
} mycolor;
If ((fp=fopen (BMP, "rb"))==NULL)
return 0;
Targetfp=fopen (dat, "wb");
Fseek (fp, 18, SEEK_SET);
Iw=0;
Ih=0;
Fread (& amp; Iw, 4, 1, fp);
Fread (& amp; Ih, 4, 1, fp);
If (iw==0 & amp; & Ih==0 & amp; & Iw> 640 & amp; & Ih> 480)
{
The fclose (fp);
The fclose (targetfp);
return 0;
} iw -;
Ih -;
Scan_times=iw/8 + 1;
Scan_pixs=scan_times * 4;
Fputc (iw % 256, targetfp);
Fputc (iw/256, targetfp);
Fputc (ih % 256, targetfp);
Fputc (ih/256, targetfp); Fseek (fp - scan_pixs SEEK_END);
for(j=0; j{nowpos=0;
Fread (scanline scan_pixs, 1, fp); Fseek (fp, - scan_pixs * 2, SEEK_CUR);
For (n=3; N>=0; N -)
{the for (I=0; i{workpos=0;
for(k=0; K<4. K++)
{mycolor.value=https://bbs.csdn.net/topics/scanline [I] * 4 + k; C [k * 2]=color ch] is [mycolor. Color. C=color [k * 2 + 1] [mycolor. Color. Cl];
}
for(k=0; K<8; K++) workpos +=(c [k] & gt;> N& 1) & lt; <(7 - k); Workline [nowpos]=workpos; Nowpos++;
}
}
Fwrite (workline, scan_pixs, 1, targetfp);
}
The fclose (fp);
The fclose (targetfp);
return 1; }
The main ()
{int n;
Int gdriver=VGA;
Int gmode=VGAHI;

_16file char bmpfile [13], [13]={0};
The FILE * fp.
Struct FFBLK * ff;
Initgraph (& amp; Gdriver, & amp; Gmode, "C: \ \ BORLANDC \ \ BGI");
Setbkcolor (BLUE);
Printf (" Now begin! \n");
Puts (" both Please select: ");
Printf (" 0 - exit, 1 -- bitmap file \ n ");
While (1)
{n=getch ();
The switch (n)
{0 case: the continue;
Case '0' : exit (0);
Case '1' :
{printf (" Input BMP file: ");
Gets (bmpfile);
Goto OUT;
}
}
}
OUT:
Strcpy (_16file, "dat"); if(! Bmp_to_dat (bmpfile _16file))
{puts (" Can not open the file! \n");
getch();
closegraph();
exit(0);
}

Fp=fopen (_16file, "rb"); Findfirst (_16file, ff, FA_ARCH); If ((buffer=malloc (ff - & gt; Ff_fsize))==NULL) exit (0);
N=0;
while(! The feof (fp))
{buffer [n]=fgetc (fp);
N++;
}
Cleardevice ();
Putimage (100100, buffer, COPY_PUT);

getch();
closegraph();
Free (buffer);

The fclose (fp);
return 0; }
Code to run out, picture is garbled, shown on the BBS, can use in 2004, why can't I use now, programming BBS

CodePudding user response:

Turbo C, so the old IDE, who want to help you all difficult,
Had better use popular IDE, good communication, it is easy to search solution, there is a problem,

CodePudding user response:

reference 1st floor ctrigger response:
Turbo C, so old IDE, who want to help you all difficult,
Had better use popular IDE, good communication, the problem is solved and easy to search,,

School persecuted, or who will be using this stuff

CodePudding user response:

Easyx?

CodePudding user response:

The use of TC in DosBox?

CodePudding user response:

DosBox test in the building of the code is allowed, it is important to note that the display BMP need 16 color, size, less than 64 KB

  • Related