当前位置: 代码迷 >> C语言 >> [求助]turbo c 3.0显示BMP
  详细解决方案

[求助]turbo c 3.0显示BMP

热度:814   发布时间:2005-07-19 12:56:00.0
[求助]turbo c 3.0显示BMP
今天路过贵宝地,看了上去回帖率很高,决定把我想问的问题在这问一问,希望大家咄咄帮忙
操作系统:WIN2000 编译环境:turbo c 3.0 目的: 显示256色 320X200的bmp图象文件 问题:我正在看《c游戏编程入门到精通》,看到显示bmp文件时,运行他给的代码,显示不出图象, 13H图形模式。 下面将给出bmp文件结构和程序代码供大家参考,看我到底什么地方出了问题 bmp文件结构: 1,文件信息区(14字节) typedef struct BMP_file{...}bitmapfile; 2,图象信息区(40字节) typedef struct BMP_info{...}bitmapinfo; 3,调色版区(1024字节) typedef struct 4,图象存储区(64000字节) bmp文件完整的结构定义: typedef struct bmp_picture_tp { bitmapfile file; bitmapinfo info; RGB_BMP palette[256]; char far *buffer; } bmp_picture, *bmp_picture_ptr; 程序代码: //-----------------------program start #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; //bug1 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("Not a BMP file!\n"); exit(1); } if(bmp_ptr->info.biCompression!=0) { printf("Can not display a compressed BMP file!\n"); exit(1); } if(bmp_ptr->info.biBitCount!=8) { printf("Not a index 16color BMP file!\n"); exit(1); } } void BMP_Load_Screen(char *bmp) { int i,fp; bmp_picture bmp256; char *file_name; //bug2 if ((fp=open(bmp,O_RDONLY))==1) return; read(fp,&bmp256.file,sizeof(bitmapfile)); read(fp,&bmp256.info,sizeof(bitmapinfo)); Check_Bmp((bmp_picture_ptr)&bmp256);//u can ingore it // lseek(fp,54,0); for (i=0;i<256;i++) { read(fp,&bmp256.palette[i].blue,1); read(fp,&bmp256.palette[i].green,1); read(fp,&bmp256.palette[i].red,1); read(fp,&bmp256.palette[i].reserved,1); bmp256.palette[i].blue=bmp256.palette[i].blue>>2; bmp256.palette[i].green=bmp256.palette[i].green>>2; bmp256.palette[i].red=bmp256.palette[i].red>>2; } for (i=0;i<256;i++) Set_BMP_Palette_Register(i,(RGB_BMP_ptr)&bmp256.palette[i]); for(i=SCREEN_HEIGHT-1;i>=0;i--) //bug4 { lseek(fp,1078+(long)(SCREEN_HEIGHT-i-1)*SCREEN_WIDTH,0); read(fp,&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,&inregs,&outregs); } int main() { Set_Video_Mode(VGA256); BMP_Load_Screen("256.bmp"); getch(); //bug3 Set_Video_Mode(TEXT_MODE); } //-----------------------program end "//bug1-4"是我加上去的标记,下面给出他们的说明 bug1:编译时出现的error。我的解决办法:在"=("后面加上"unsigned "。 bug2:编译时出现的warning。我的解决办法:去掉所在那一行。 bug3:编译时出现error。我的解决办法:更改为"getchar();" bug4:运行时,for循环语句没有出来,估计显示不出来与这里有关 最后:罗嗦了这么多,浪费了您的宝贵时间,实在抱歉的很。 我花了一周时间反复看了这段代码,对于显示的基本思路还是有了些了解,但到了最后居然显示不出来,对初学者的我来说,实在是太打击我了,还请各位大侠不吝赐教,我将感激不尽。 回贴或者发我邮箱hhw_Marz@tom.com都行哈
搜索更多相关的解决方案: turbo  BMP  操作系统  bmp  

----------------解决方案--------------------------------------------------------
有没有路过的大侠帮帮我啊,我真的已经卡在这里了,实在必须过这关啊
----------------解决方案--------------------------------------------------------
哎,我都无语了....

给你介绍几个帖子,也许你会有兴趣
http://sundelinustc.tianyablog.com/blogger/post_show.asp?BlogID=16576&amp;PostID=1796893&amp;idWriter=0&amp;Key=0
http://www.bc-cn.net/bbs/dispbbs.asp?boardID=5&amp;ID=4565
http://bbs.bc-cn.net/bbs/dispbbs.asp?boardID=5&amp;ID=11600
----------------解决方案--------------------------------------------------------
    你介绍的有个是24位的BMP显示,而且我运行他的程序也是一样可以编译通过,但输入BMP文件后没有显示直接回到TC编辑界面

    今天我还发现我这里画点函数putpixel(int x,int x,int color)用不了,当然加上了&lt;graphics.h&gt;头文件了的,
----------------解决方案--------------------------------------------------------
不是让运行程序,程序你是不一定能运行成功的,因为每个人的显卡中断调用都可能不一样

而是让你看看应该是如何处理BMP文件的

24位BMP和高彩色BMP的程序你可以不看,我以为你会感兴趣,就顺手发上来了
----------------解决方案--------------------------------------------------------
以下是引用天空之城在2005-7-20 11:42:41的发言: 不是让运行程序,程序你是不一定能运行成功的,因为每个人的显卡中断调用都可能不一样 而是让你看看应该是如何处理BMP文件的 24位BMP和高彩色BMP的程序你可以不看,我以为你会感兴趣,就顺手发上来了
提到点子上了,我也觉得与显卡有关,但我对这块不熟, 我怀疑与这个设置有关,应该怎样设置,还请教教 我 void Set_Video_Mode(int mode) { union REGS inregs,outregs; inregs.h.ah=0; inregs.h.al=(unsigned char)mode; int86(0x10,&inregs,&outregs); }
----------------解决方案--------------------------------------------------------
我同学告诉我说是,可能是outp函数不支持我的显卡,所以才是黑屏没图象,不知道是不是这样,如果是的话,怎样找到支持我这种显卡的outp函数,
我的显示器是IBM,显卡是Intel 82845G

[此贴子已经被作者于2005-7-21 11:16:16编辑过]



----------------解决方案--------------------------------------------------------