一个简单的问题??

xuyangjie 2004-04-02 08:27:47
如何用一段c程序来打开一个图片文件,在屏幕上显示出来?????
...全文
36 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuyangjie 2004-04-09
  • 打赏
  • 举报
回复
不好意思,但如何使用呢???
xuyangjie 2004-04-08
  • 打赏
  • 举报
回复
没想到如此复杂,谢谢各位,路途漫长啊!!!!
bideyore 2004-04-04
  • 打赏
  • 举报
回复
好啊,我喜欢,前一阵子刚做过,又有参考了!谢谢BRO.小张!
bideyore 2004-04-04
  • 打赏
  • 举报
回复
不好意思,是小涛...
rorot 2004-04-04
  • 打赏
  • 举报
回复
C语言之家有256色位图的显示。
还有一个变态的写了一个能支持好几种显卡的显示真彩色位图的C源代码。尽管那人用了国外的BGI库,俺还是狠佩服那个变态啊。晕啊~
楼主如果要了解显示图片的细节,不妨去C语言之家看看。
newegg2002 2004-04-02
  • 打赏
  • 举报
回复
up以自勉,,,
wshcdr 2004-04-02
  • 打赏
  • 举报
回复
友情UP下
bm1408 2004-04-02
  • 打赏
  • 举报
回复
呵呵!
又是这个例子!
wythust 2004-04-02
  • 打赏
  • 举报
回复
显示.bmp比较典型,主要有两大难点:图像存储区的读取和调色板区的读取,给个例子给你,自已慢慢研究吧:

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


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--)
{
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");/*读取256.bmp文件*/
getch();

Set_Video_Mode(TEXT_MODE);

}

70,037

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧