151.动态显示位图

简介: 151.动态显示位图
#include "stdio.h"
#include "dir.h"
#include "dos.h"
#include "graphics.h"
char *malloc();/*malloc转换*/
char bmp_to_dat(char *bmp,char *dat)
/*将16色BMP文件转换为可以用putimage输出的格式,bmp为原BMP文件,dat为转化文件*/
{
  unsigned char c[8],scan_times,scan_pixs;
  unsigned char workpos;int i,j,k,n,nowpos,iw,ih;
  static int color[16]={0,4,2,6,1,5,3,7,8,12,10,14,9,13,11,15};
  unsigned char workline[640],scanline[640];
  FILE *fp,*targetfp;
  union
  {
    unsigned char value;
    struct
    {
      unsigned cl:4;
      unsigned ch:4;
    }color;
  }mycolor;
  if((fp=fopen(bmp,"rb"))==NULL)return(0);
  targetfp=fopen(dat,"wb");
  fseek(fp,18,SEEK_SET);
  iw=0;ih=0;
  fread(&iw,4,1,fp);    /*读图像宽度*/
  fread(&ih,4,1,fp);    /*读图像高度*/
  if(iw==0&&ih==0&&iw>640&&ih>480)
  {fclose(fp);fclose(targetfp);return(0);}
  iw--;ih--;      /*∵putimage中的长宽比实际数值少1*/
  scan_times=iw/8+1;    /*行处理单位数*/
  scan_pixs=scan_times*4;   /*行像素字节数∵1单位=4字节*/
  fputc(iw%256,targetfp);   /*填充信息头:长、宽部分*/
  fputc(iw/256,targetfp);
  fputc(ih%256,targetfp);
  fputc(ih/256,targetfp);
  fseek(fp,-scan_pixs,SEEK_END);
  for(j=0;j<=ih;j++)
  {nowpos=0;
  fread(scanline,scan_pixs,1,fp);
  fseek(fp,-scan_pixs*2,SEEK_CUR);
  for(n=3;n>=0;n--)   /*解码4个位面*/
  {for(i=0;i<scan_times;i++)  /*解码各编码单位*/
  {workpos=0;
    for(k=0;k<4;k++)    /*分离出8个像素*/
    {mycolor.value=scanline[i*4+k];
  c[k*2]=color[mycolor.color.ch];
  c[k*2+1]=color[mycolor.color.cl];
    }
    for(k=0;k<8;k++)workpos+=(c[k]>>n&1)<<(7-k);
    workline[nowpos]=workpos;nowpos++;
  }}
  fwrite(workline,scan_pixs,1,targetfp);
  }
  fclose(fp);fclose(targetfp);
  return(1);
}
main()
{
  int gd=VGA,gm=VGAHI,n;
  char *buffer,bmpfile[13],_16file[13]={0};
  FILE *fp;
  struct ffblk *ff;
  /*registerbgidriver(EGAVGA_driver);*/
  initgraph(&gd,&gm,"C:\\tc");
  printf("Now start to display 16 color bmp.\n\n");
  puts("Please choice: ");
  printf("0. Quit \n1. BMP file name\n");
  while(1)
  {
    n=getch();
    switch(n)
    {
    case 0  :continue;
    case '0':exit(0);
    case '1':
      {
        printf("Please input BMP file name(*.bmp):");
        gets(bmpfile);
        goto OUT;
      }
    }
  }
OUT:
  strncpy(_16file,bmpfile,strlen(bmpfile)-3);
  strcat(_16file,"dat");
  if(!bmp_to_dat(bmpfile,_16file))
  {
    puts("Can't open file!");
    closegraph();
    exit(0);
  }
  fp=fopen(_16file,"rb");
  findfirst(_16file,ff,FA_ARCH);
  if((buffer=malloc(ff->ff_fsize))==NULL)exit(0);
  n=0;
  while(!feof(fp))
  {
    buffer[n]=fgetc(fp);
    n++;
  }
  for(n=0;n<100;n++)
  {
    putimage(350-n,n/2,buffer,COPY_PUT);
  }
  getch();
  closegraph();
  free(buffer);
  fclose(fp);
}
相关文章
|
搜索推荐 UED
ChatGPT的推理过程
【1月更文挑战第8天】ChatGPT的推理过程
315 3
ChatGPT的推理过程
|
分布式计算 安全 Hadoop
HBase启动时有进程webUI不显示HRegionServer各种情况解决方案
HBase启动时有进程webUI不显示HRegionServer各种情况解决方案
583 0
|
存储 域名解析 缓存
|
JavaScript
Vue学习之--------路由的query、params参数、路由命名(3)(2022/9/5)
这篇文章详细介绍了Vue路由中的query参数、命名路由、params参数以及props配置的使用方式,并通过实际项目案例展示了它们在开发中的应用和测试结果,同时解释了`<router-link>`的`replace`属性如何影响浏览器历史记录。
Vue学习之--------路由的query、params参数、路由命名(3)(2022/9/5)
|
供应链 监控 物联网
未来已来:探索区块链、物联网与虚拟现实技术的融合革新
【7月更文挑战第18天】 在数字技术不断演进的今天,区块链、物联网(IoT)和虚拟现实(VR)等新兴技术正逐渐改变我们的工作和生活方式。本文旨在深入探讨这些技术的独特发展趋势及其在多个行业中的创新应用。我们将看到,随着技术的成熟和应用场景的拓展,这些领域不仅独立发展,更在相互融合中催生出新的增长点和解决方案。
|
Go
Go 1.21 新内置函数:min、max 和 clear
Go 1.21 版本已经正式发布,它带来了许多新特性和改进。其中引入了的三个新内置函数:max、min 和 clear,接下来的内容将详细介绍这些函数的用途和特点。
442 1
|
JavaScript IDE 开发工具
HarmonyOS3项目扩展名ets文件和ts文件有什么区别
HarmonyOS3项目扩展名ets文件和ts文件有什么区别
686 0
|
JavaScript
Vue.js学习详细课程系列--共32节(4 / 6)
Vue.js学习详细课程系列--共32节(4 / 6)
101 0
|
JavaScript 前端开发 PHP
34、文件上传 -- 绕过JS验证
34、文件上传 -- 绕过JS验证
86 0
|
存储 人工智能 安全
网络信息系统安全的发展演变
网络信息系统安全随着通信技术和信息技术的发展,大致经历了通信保密年代、计算机系统安全年代、信息系统网络安全年代、网络空间安全年代。
467 0