2024年4月29日发(作者:)
在TC2.0下,隶属于16位子系统,所以int是2字节,long是4字节,char是1字节。绘
图系统模式是VGA,颜色当然也很有限,所以读取bmp像素后需要把像素颜色转换为“最
近”的已有VGA颜色。用int GetColor(int r,int g,int b)实现返回一个颜色值(color code)。用
putpixel(int x,int y,int color)绘制一个像素。
(读bmp处尚有问题,会有读取像素时未读出字节的问题出现,原因尚待查。。。。)
#include
#include
#include
#include
#include
int MAX_Y=480;
int MAX_X=640;
int COLORS[15][4]=
{
/* Red Green Blue,code */
{ 0, 0, 0, 0}, /* Black
{ 0, 0,255, 1}, /* Blue */
{ 0,128, 0, 2}, /* Green
{ 0,255,255, 3}, /* Cyan
{255, 0, 0, 4}, /* Red
{255, 0,255, 5}, /* Magenta
{165, 42, 42,20}, /* Brown
{211,211,211, 7}, /* LightGray
{169,169,169,56}, /* DarkGray
{173,216,230,57}, /* LightBlue
{144,238,144,58}, /* LightGreen
{238,144,144,60}, /* LightRed?
{238,144,238,61}, /* LightMegenta?
{255,255, 0,62}, /* Yellow
{255,255,255,63} /* WhITe
};
/* pixel : keep channel order wITh readfile order */
typedef struct _PIXEL
{
unsigned char b;
unsigned char g;
unsigned char r;
} PIXEL;
typedef struct _BITMAPFILEHEADER
{
int type;
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
long fileSize;
long reserved;
long offbITs;
} BITMAPFILEHEADER,*PBITMAPFILEHEADER;
typedef struct _BITMAPINFOHEADER
{
long dwSize;
long width;
long height;
int planes;
int bpp;
long compression;
long sizeImage;
long hResolution;
long vResolution;
long colors;
long importantColors;
} BITMAPINFOHEADER,*PBITMAPINFOHEADER;
int GetColor();
void ReadImage();
void DrawAxes();
void main()
{
int driver,mode,i,j;
char c,string[255],filename[255];
printf("input the filename of bITmap file:n");
scanf("%s",filename);
driver=DETECT;
mode=IBM8514HI;
inITgraph(&driver,&mode,"");
/* draw a bITmap */
ReadImage(filename);
c=getch();
closegraph();
}
/* read pixels from imagefile and display */
void ReadImage(char* filename)
发布评论