用dos方式下显示bmp文件 ( 积分: 200 )

  • 主题发起人 主题发起人 tswhq
  • 开始时间 开始时间
T

tswhq

Unregistered / Unconfirmed
GUEST, unregistred user!
想做登陆画面:
1能够显示bmp背景(640*480 256)
2能够在指定的位置显示bmp文件
3接受输入(包括左右上下光标,1,2,3....回车等)
4返回数值供批处理判断
最好是Tc2.0的或delphi 6.0
 
想做登陆画面:
1能够显示bmp背景(640*480 256)
2能够在指定的位置显示bmp文件
3接受输入(包括左右上下光标,1,2,3....回车等)
4返回数值供批处理判断
最好是Tc2.0的或delphi 6.0
 
帮顶

--------签名档---------------------------

惊爆开源站

http://www.source520.com

80G源码电子书免费免注册下载,大量精辟技术文档库随时更新
 
这是我上大学时候写的代码,已经提供了put_256pixel函数,你剩下的工作就是读写bmp格式,然后逐点绘图就行了,以前帮别人做过还原卡,这个代码是经过市场测试的。

void put_256pixel(int x,int y,unsigned char color);
void set_mode ( int m );
void set_page ( int bank_number );
void init256();
void close256();

void puts256(unsigned char *s,int x,int y,int color)
{ char text_flag,fix_length=0,th,tw,i,j,mat[32]={0},canput;
char text_h;
unsigned char qh,wh;

unsigned char *p,*ROM;
struct REGPACK reg;

int handle;
long offset;

text_h=16;
handle=_open("hzk16",O_RDONLY|O_BINARY);
if(handle==-1)
{ printf("can't open hzk16");
exit(0);
}


reg.r_ax=0x1130;
reg.r_bx=0x0600;
intr(0x10,&reg);
ROM=(unsigned char*)MK_FP(reg.r_es,reg.r_bp); /*获得ROM字符集首址*/

while(*s!=0)
{ if(*s>0xa0&&*(s+1)>0xa0) /*read zi_mo from hzk restore to mat[32]*/
{ qh=*s-0xa0;
wh=*(s+1)-0xa0;
offset=(94*(qh-1)+wh-1)*32L;
lseek(handle,offset,SEEK_SET); /* from begining */
_read(handle,mat,32);
text_flag=1 ; /* it is a han_zi*/
th=16;
tw=16;
s=s+2;
}
else
{ tw=8;
th=16;
p=ROM+(*s)*16;
memcpy(mat,p,16); /* 16 bytes every character */
text_flag=0; /*it is a character */
s=s+1;
}
for(j=0;j<th;j++)
for(i=0;i<tw;i++)
{ if(text_flag!=0) /* a han_zi */
canput=((0x80>>i%8)&amp;mat[2*j+i/8]);
else
canput=((mat[j]>>(7-i))&amp;1);
if(canput)
{ fix_length=(text_flag&amp;&amp;text_h==14);
put_256pixel(i+x+fix_length,y+j,color);
}
}
if(text_flag!=0)
x=x+16;
else
x=x+8;
} /*end while*/
_close(handle);
}

void set_mode ( int m )
{
union REGS i, o ;

i.x.ax = 0x4f02 ;
i.x.bx = m ;
int86 ( 16, &amp;i, &amp;o ) ;
}

void set_page ( int bank_number )
{
union REGS i, o ;
i.x.ax = 0x4F05 ;
i.x.bx = 0 ;
i.x.dx = bank_number ;
int86 ( 16, &amp;i, &amp;o ) ;
}

void init256()
{
set_mode(0x103);
}

void close256()
{
set_mode(0x03);
}
 
void put_256pixel(int x,int y,unsigned char color);//没有此过程呀
 
#include<io.h>
#include<stdio.h>
#include<dos.h>
#include<string.h>
#include<math.h>
#include<stdio.h>
#include<bios.h>
#include<mem.h>
#include<fcntl.h>
#include<stdlib.h>
#include<conio.h>

#define SCREEN_HEIGHT 200
#define SCREEN_WIDTH 320

#define PALETTE_MASK 0x3c6
#define PALETTE_REGISTER_RD 0x3c7
#define PALETTE_REGISTER_WR 0x3c8
#define PALETTE_DATA 0x3c9

#define VGA256 0x13
#define TEXT_MODE 0x03

unsigned char far *video_buffer=(char far *)0xA0000000L;

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_ptr;

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_ptr 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_ptr)
{
if(bmp_ptr->file.bfType!=0x4d42)
{
printf(&quot;Not a BMP file!/n&quot;);
exit(1);
}
if(bmp_ptr->info.biCompression!=0)
{
printf(&quot;Can not display a compressed BMP file!/n&quot;);
exit(1);
}
if(bmp_ptr->info.biBitCount!=8)
{
printf(&quot;Not a index 16color BMP file!/n&quot;);

exit(1);
}
}


void BMP_Load_Screen(char *bmp)
{
int i,fp;
bmp_picture bmp256;
char *file_name;
if ((fp=open(bmp,O_RDONLY))==1)
return;

read(fp,&amp;bmp256.file,sizeof(bitmapfile));
read(fp,&amp;bmp256.info,sizeof(bitmapinfo));

Check_Bmp((bmp_picture_ptr)&amp;bmp256);//u can ingore it
// lseek(fp,54,0);

for (i=0;i<256;i++)
{
read(fp,&amp;bmp256.palette.blue,1);
read(fp,&amp;bmp256.palette.green,1);
read(fp,&amp;bmp256.palette.red,1);
read(fp,&amp;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_ptr)&amp;bmp256.palette);

for(i=SCREEN_HEIGHT-1;i>=0;i--)
{
lseek(fp,1078+(long)(SCREEN_HEIGHT-i-1)*SCREEN_WIDTH,0);
read(fp,&amp;video_buffer[i*SCREEN_WIDTH],SCREEN_WIDTH);
}
close(fp);

}

void Set_Video_Mode(int mode)
{
union REGS inregs,outregs;
inregs.h.ah=0;
inregs.h.al=(unsigned char)mode;
int86(0x10,&amp;inregs,&amp;outregs);
}

int main()
{
Set_Video_Mode(VGA256);
BMP_Load_Screen(&quot;256.bmp&quot;);
getch();

Set_Video_Mode(TEXT_MODE);

}

网上摘的,为何不出人呀?????
 
你可以用delphi 呀,搞个黑色的屏幕(模拟全屏),成不?
这样不就简单多了。
windows>run>cmd 哪个窗口.
 
我用纯dos,大侠
 
C,又是C,再见C...郁闷...建议楼主去搜索一下&quot;TC2下实现读取16色BMP位图&quot;,能得到你需要的
 
接受答案了.
 
后退
顶部