*)0xA0000000L;
int color=7,bkcolor=7;
typedef struct BMP_file
{
unsigned int bftype;
unsigned long bfsize;
unsigned int reserved1;
unsigned int reserved2;
unsigned long bfOffset;
}
bitmapfile;
typedef struct BMP_info
{
unsigned long bisize;
unsigned long biwidth;
unsigned long biheight;
unsigned int biplanes;
unsigned int bibitcount;
unsigned long bicompression;
unsigned long bisizeImage;
unsigned long bixpolspermeter;
unsigned long biypelsPermeter;
unsigned long biclrused;
unsigned long biclrImportant;
}
bitmapinfo;
typedef struct RGB_BMP_TYP{
unsigned char blue;
unsigned char green;
unsigned char red;
unsigned char reserved;
}RGB_BMP,*RGB_BMP_PRT;
typedef struct bmp_picture_typ{
bitmapfile file;
bitmapinfo info;
RGB_BMP palette[256];
char far *buffer;
} bmp_picture,*bmp_picture_ptr;
void set_bmp_palette_register(int index,RGB_BMP_PRT color){
outp(PALETTE_MASK,0xff);
outp(PALETTE_REGISTER_WR,index);
outp(PALETTE_DATA,color->red);
outp(PALETTE_DATA,color->green);
outp(PALETTE_DATA,color->blue);
}
void check_bmp(bmp_picture_ptr bmp){
if(bmp->file.bftype!=0x4d42)
{ printfhz("不是BMP文件",100,100);
exit(1);}
if(bmp->info.bicompression!=0){
printfhz("BMP文件被压缩过的无法打开",100,120);
exit(1);}
if(bmp->info.bibitcount!=8){
printfhz("NO这不是256色图片",100,120);
exit(1); }
}
示例演示代码
/*.......................................................*/
#include"bmp.c"
#include"vga256.c"
#include"hz.c"
void fastbmp(int y,char far *video_b){ /*BMP文件显示分页显示涵数 */
int xx=0,jj;
static int t=0;
long i;
for(jj=0;jj
>16;
i&=0xffff;
if(t!=xx) fy(xx);
*(video_buffer+i)=video_b[jj];
t=xx; } }
void bmpopen(char *bmp){ /*打开BMP文件 */
int i,fp,ii;
bmp_picture bmp256;
char *file_name;
if((bmp256.buffer=(char *)malloc(maxx))==NULL)
{
getch(); exit(1);
}
if((fp=open(bmp,O_RDONLY))==1)
return;
printfhz("打开文件成功",200,100);
getch();
read(fp,&bmp256.file,sizeof(bitmapfile));
read(fp,&bmp256.info,sizeof(bitmapinfo));
check_bmp((bmp_picture_ptr)&bmp256);
lseek(fp,54,0);
for(i=0;i<256;i++){
read(fp,&bmp256.palette.blue,1);
read(fp,&bmp256.palette.green,1);
read(fp,&bmp256.palette.red,1);
read(fp,&bmp256.palette.reserved,1);
bmp256.palette.blue=bmp256.palette.blue>>2;
bmp256.palette.green=bmp256.palette.green>>2;
bmp256.palette.red=bmp256.palette.red>>2;
}
for(i=0;i<256;i++)
set_bmp_palette_register(i,(RGB_BMP_PRT)&bmp256.palette);
for(i=maxy-1;i>=0;i)
{
lseek(fp,1078+(long)(maxy1)*maxx,0);
read(fp,bmp2
key=getch(); /*读取该键*/
if(!key) /*如果低位是0 则读取高位*/
{
key=getch(); /*读取高位*/
if(key==72||key==73)
{
if(y>0) y=y-4;
}
if(key==80)
{
if(y<600) y=y+4;
}
if(key==75)
{
if(x>0) x=x-5;
}
if(key==77)
{
if(x<720) x=x+5;
}
}
else{ /*如果低位是0 那就是普通按键*/
if(key=='w')
{
if(y>0) y=y-4;
}
if(key=='x')
{
if(y<600) y=y+4;
}
if(key=='a')
{
if(x>0) x=x-5;
}
if(key=='d')
{
if(x<720) x=x+5;
}
if(key=='q') exit(1);
}
}
}
本文来源:https://www.2haoxitong.net/k/doc/7cd9f71452d380eb62946dbf.html