鱼C论坛

 找回密码
 立即注册
查看: 1460|回复: 1

求助,字符画无法正常显示

[复制链接]
发表于 2021-1-30 22:43:08 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
如题,就左右错位画对不上位置,字符和视频的内容对不上
提取码:cs0c
  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include<time.h>
  6. BITMAPFILEHEADER fileHead;      //文件信息头
  7. BITMAPINFOHEADER infoHead;      //位图信息头
  8. RGBQUAD pColorTable[256];       //颜色表指针
  9. unsigned char *pBmpBuf;         //图像数据指针
  10. int bmpWidth;          //图像的宽
  11. int bmpHeight;        //图像的高
  12. int biBitCount;       //每像素位数
  13. int lineByte;         //每行的字节数
  14. unsigned char a[1000][1000];
  15. unsigned char *Pre = NULL;
  16. char *out;
  17. char info[] = {"$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_+~<>i!lI;:,"^` ."};//根据字符的复杂到简单排列
  18. int len ,reg = 1;
  19. clock_t stime,ftime,ltime,lt;


  20. #define name "picture\\wrxq"
  21. #define frame 7196//总帧数

  22. //还可以通过控制Print函数中打印的行数以及列数来控制更新速率
  23. #define clearDegree 2 //隔几帧读一次
  24. #pragma comment(lib, "WINMM.LIB")



  25. int Read(const char *bmpName);
  26. int Run(const char *bmpName);     /*函数原型*/
  27. void Print();
  28. void Pos(int x, int y);



  29. int main(int argc, char *argv[])
  30. {
  31.         out = (char *)malloc(sizeof(char) * 40000);
  32.         system("mode con cols=4000 lines=4000");
  33.         system("color F0");
  34.        
  35.         len = strlen(info) - 1;
  36.         Run(name);
  37.         free(out);
  38.         return 0;
  39. }

  40. int Run(const char *bmpName)
  41. {
  42.         register int i;
  43.         int count = 0,temp = frame;
  44.         char path[30] = "\0";
  45.         char format[15];
  46.         while(temp > 0)
  47.         {
  48.                 ++count;
  49.                 temp /= 10;
  50.         }
  51.         sprintf(format,"%s%dd%s","%s%0",count,"%s");
  52.         PlaySound("wrxq.wav", NULL, SND_FILENAME | SND_ASYNC);
  53.         stime = lt = clock();
  54.         printf("%ld",stime);
  55.         for(i = 0;i < frame;)
  56.         {
  57.                         if(i % 30 == 0)
  58.                 {
  59.                         reg = 94;
  60.                 }
  61.                 ftime = clock();
  62.                 if((ftime - stime) >= reg)
  63.                 {
  64.                         reg =95;
  65.                         path[0] = '\0';
  66.                         sprintf(path,format,bmpName,i,".BMP");
  67.                         i+=3;
  68.                         stime = ftime;
  69.                         Read(path);
  70.                         Print();
  71.                 }
  72.         }
  73.         ltime = clock();

  74.         if(Pre)
  75.                 free(Pre);
  76.         system("cls");
  77.         return 0;
  78. }
  79. void Print()
  80. {
  81.         int i,j;
  82.         int x = 0;
  83.         Pos(0,0);
  84.         for(i = 17;i < bmpHeight - 17;++i)
  85.         {
  86.                 if(i % clearDegree != 0)
  87.                         continue;
  88.                 for(j = 0;j < bmpWidth;++j)
  89.                         out[x++] = info[(int)(a[i][j]/256.0*len)];
  90.                 out[x++] = '\n';       
  91.         }
  92.         out[x] = '\0';
  93.         printf("%s",out);
  94. }
  95. int Read(const char *bmpName)
  96. {
  97.         FILE *fp = fopen(bmpName,"rb");              /*二进制读方式打开指定的图像文件*/
  98.         register int i,j;
  99.         unsigned char * pix = NULL;
  100.         if(fp==NULL)
  101.                 return 0;
  102.         fread(&fileHead,sizeof(BITMAPFILEHEADER),1,fp);    /*读文件信息头*/
  103.         fread(&infoHead,sizeof(BITMAPINFOHEADER),1,fp);    /*读位图信息头*/
  104.         bmpWidth=infoHead.biWidth;     /*获取图像宽,高,每像素所占位数等信息 */
  105.         bmpHeight=infoHead.biHeight;
  106.         biBitCount=infoHead.biBitCount;
  107.         lineByte=(bmpWidth*biBitCount/8+3)/4*4;    /*计算每行字节数(必须是4的倍数)*/

  108.         if(Pre == NULL)
  109.         {
  110.                 pix=(unsigned char *)malloc(lineByte+1);
  111.                 Pre = pix;
  112.         }
  113.         else
  114.                 pix = Pre;
  115.         if(pix == NULL)
  116.                 return 0;
  117.         for(i = 0;i < bmpHeight;++i)
  118.         {
  119.                 fread(pix,1,lineByte,fp);
  120.                 for(j = 0;j < bmpWidth;++j)
  121.                 {
  122.                         a[bmpHeight-i-1][j] = (int)((unsigned char)(pix[j*3+2] * 0.3 + pix[j*3+1] * 0.59 + pix[j*3] * 0.11));
  123.                 }
  124.         }
  125.         fclose(fp);
  126.         return 0;
  127. }

  128. void Pos(int x, int y)//设置光标位置
  129. {//要注意这里的x和y与我们数组的x和y是反的
  130.         COORD pos;
  131.         HANDLE hOutput;
  132.         pos.X = x;
  133.         pos.Y = y;
  134.         hOutput = GetStdHandle(STD_OUTPUT_HANDLE);//返回标准的输入、输出或错误的设备的句柄,也就是获得输入、输出/错误的屏幕缓冲区的句柄
  135.         SetConsoleCursorPosition(hOutput, pos);
  136. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2021-1-30 22:44:56 | 显示全部楼层
使用的是Visual C++ 6.0编译环境,win10系统
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-5-2 00:55

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表