中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

中国DOS联盟论坛
现在时间是 2026-08-01 03:34
中国DOS联盟论坛 » DOS开发编程 & 发展交流 (开发室) » [求助]TC加载BMP图片出错! 查看 1,416 回复 8
楼 主 [求助]TC加载BMP图片出错! 发表于 2003-10-23 00:00 ·  中国 陕西 西安 电信
初级用户
★★
忍者
积分 376
发帖 86
注册 2003-10-16 00:00
22年会员
UID 11361
性别 男
状态 离线
我在用TC编界面时,加载BMP图片,编译成功,但却没有显示图片。
请问:这种情况一般是什么问题。查找了好多资料,都差不多!
以C语言软件开发为主:http://sunny1979.icpcn.com
2 发表于 2003-10-24 00:00 ·  中国 湖南 长沙 电信
初级用户
★★
积分 255
发帖 54
注册 2003-10-24 00:00
22年会员
UID 11864
性别 男
状态 离线
能看看你的源码吗?
3 发表于 2003-10-26 00:00 ·  中国 陕西 西安 长安区 电信
初级用户
★★
忍者
积分 376
发帖 86
注册 2003-10-16 00:00
22年会员
UID 11361
性别 男
状态 离线
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

#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;
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;
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);
lseek(fp,54,0);

for (i=0;i>2;
bmp256.palette.green=bmp256.palette.green>>2;
bmp256.palette.red=bmp256.palette.red>>2;
}
for (i=0;i=0;i--)
{

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();

Set_Video_Mode(TEXT_MODE);

}
以C语言软件开发为主:http://sunny1979.icpcn.com
4 发表于 2003-10-27 00:00 ·  中国 湖南 长沙 电信
初级用户
★★
积分 255
发帖 54
注册 2003-10-24 00:00
22年会员
UID 11864
性别 男
状态 离线
*_* 能不能适当加一点注释啊?

写程序要注意可读性啊。
5 发表于 2003-10-30 00:00 ·  中国 广东 深圳 福田区 电信
初级用户
积分 117
发帖 4
注册 2003-10-30 00:00
22年会员
UID 12166
性别 男
状态 离线
都没写显示的代码
你怎么可能看得见图片?
况且还有错误!
6 发表于 2003-10-30 00:00 ·  中国 湖北 武汉 联通
高级用户
★★
积分 677
发帖 194
注册 2003-09-13 00:00
22年会员
UID 9778
性别 男
状态 离线
你用过QB没有啊??
用过的话,我愿意提供一点力所能及的帮助!
7 发表于 2003-11-13 00:00 ·  中国 陕西 西安 电信
初级用户
★★
忍者
积分 376
发帖 86
注册 2003-10-16 00:00
22年会员
UID 11361
性别 男
状态 离线
void BMP_Load_Screen(char *bmp)
这不是显示代码吗?
我没用过QB谢谢你!
以C语言软件开发为主:http://sunny1979.icpcn.com
8 发表于 2003-11-14 00:00 ·  中国 湖北 武汉 鹏博士宽带
中级用户
★★
积分 286
发帖 59
注册 2003-04-08 00:00
23年会员
UID 1437
性别 男
状态 离线
不知道楼主是不是用的一本书上的源代码,好像是叫《标准VESAXXX》什么的,还是《C游戏编程从入门到精通》具体记不得了,我也用过,也是没有图像,后来利用其原理,自己重写了相关代码,没有直接用他书上的,图像就出来了,估计是他的调色板设置代码有问题。
9 发表于 2003-11-17 00:00 ·  中国 陕西 西安 电信
初级用户
★★
忍者
积分 376
发帖 86
注册 2003-10-16 00:00
22年会员
UID 11361
性别 男
状态 离线
8楼的先生,你说对了,我改了一下,可以用了。
结果放在我的主页里。点击下面!
以C语言软件开发为主:http://sunny1979.icpcn.com
论坛跳转: