- 注册时间
- 2004-8-28
- 最后登录
- 1970-1-1
|
可以不加转换直接把Bmp文件绘制到WQX屏幕上面。
没有多测试过,也不知道在实机上效率如何。
- //typedef struct tagBITMAPFILEHEADER()
- #define bfType 0 //WORD 位图文件的类型,必须为BM
- #define bfSize 2 //DWORD 位图文件的大小,以字节为单位
- #define WORDbfReserved1 6 //Byte 位图文件保留字,必须为0
- #define WORDbfReserved2 7 //Byte 位图文件保留字,必须为0
- #define bfOffBits 8 //DWORD 位图数据的起始位置,以相对于位图
- //typedef struct tagBITMAPINFOHEADER
- #define biSize 0 //DWORD 本结构所占用字节数
- #define biWidth 4 //LONG 位图的宽度,以像素为单位
- #define biHeight 8 //LONG 位图的高度,以像素为单位
- #define biPlanes 12 //WORD 目标设备的级别,必须为1
- #define biBitCount 14 //WORD 每个像素所需的位数,必须是1(双色),
- // 4(16色),8(256色)或24(真彩色)之一
- #define biCompression 16 //DWORD 位图压缩类型,必须是 0(不压缩),
- // 1(BI_RLE8压缩类型)或2(BI_RLE4压缩类型)之一
- #define biSizeImage 20 //DWORD 位图的大小,以字节为单位
- #define biXPelsPerMeter 24 //LONG 位图水平分辨率,每米像素数
- #define biYPelsPerMeter 28 //LONG 位图垂直分辨率,每米像素数
- #define biClrUsed 32 //DWORD 位图实际使用的颜色表中的颜色数
- #define biClrImportant 36 //DWORD 位图显示过程中重要的颜色数
- char ShowBmp(int bmpdat,int x,int y,int type)
- {
- char bMap[12];
- char bInfo[40];
- char buf[1600];
- long i,j;
- int w,h,dw,dl;
- //检查是否为Bmp文件
- memcpy(bMap,bmpdat,12);
- if(bMap[bfType]!=0x42||bMap[bfType+1]!=0x4d) return 0;
- //检查是不是Bit1的Bmp文件
- memcpy(bInfo,bmpdat+12,40);
- if(bInfo[biBitCount]!=1) return 0;
- memcpy(&w,bInfo+biWidth+2,2);
- memcpy(&h,bInfo+biHeight+2,2);
- //检查是不是超限
- if(w>160 || h>80 ) return 0;
- //计算需要拷贝的数据量和间隔长度
- dw=w/8;
- if(dw*8!=w) dw++;
- dl=dw/4;
- if(dl*4!=dw) dl=(dl+1)*4; else dl=dl*4;
- //将原数据转换成WriteBlock的可读取数据
- for(i=0;i<h;i++)
- {
- memcpy(buf+i*dw,bmpdat+62+dl*(h-1-i),dl);
- for(j=0;j<dw;j++) buf[i*dw+j]=buf[i*dw+j] ^ 0xff;
- }
- WriteBlock(x,y,w,h,type,buf);
- return 1;
- }
- //例子
- void main()
- {
- char fp;
- char bmpdat[1662];
- fp=fopen("/LavaData/Scr.bmp","rb");
- fread(bmpdat,1,1662,fp);
- ShowBmp(bmpdat,0,0,1);
- Refresh();
- getchar();
- }
复制代码 |
|