找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 11928|回复: 1

彩色二维码生成工具qr2.exe

[复制链接]
发表于 2017-5-14 22:35:24 | 显示全部楼层 |阅读模式
本帖最后由 happy886rr 于 2017-5-14 22:53 编辑

下载:存图片为a.zip,解压即是。(全部外链,另笔名正式由HAPPY改为LEO,以便统一不同论坛作品笔名)


QR2.EXE是一款C语言写的彩色二维码生成器,可以生成色彩斑斓的彩色码块,虽然识别效率有所下降,但微信,QQ等工具识别还是蛮快的。
编码算法借助日本QR编码规则https://github.com/lys861205/qrC ... rTest/QR_Encode.cpp。核心色彩转化代码如下:

  1. /*
  2.         CONSOLE QRCODE, COPYRIGHT@2017~2019 BY LEO, VERSION 1.0
  3.         QR2.EXE
  4. */
  5. #include <stdio.h>
  6. #include <math.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include "QR_Encode.cpp"

  10. #define BF_ZOOM        10
  11. #define BF_MARGIN 10

  12. //定义帮助说明
  13. #define HELP_INFORMATION "\
  14. QR2 version 1.0 - Console qrcode tool - Copyright (C) 2017-2019 by Leo\n\
  15. \n\
  16. Usage:\n\
  17.     qr2 [your text]\n\
  18. \n\
  19. Official website:\n\
  20.     http://www.bathome.net/thread-44143-1-1.html\n"

  21. //定义BMP头
  22. static unsigned char header[] =
  23. {
  24.         'B','M',  // magic number
  25.         0,0,0,0,  // size in bytes (set below)
  26.         0,0,0,0,  // reserved
  27.         54,0,0,0, // offset to start of pixel data
  28.         40,0,0,0, // info hd size
  29.         0,0,0,0,  // image width (set below)
  30.         0,0,0,0,  // image heigth (set below)
  31.         1,0,      // number color planes
  32.         24,0,     // bits per pixel
  33.         0,0,0,0,  // compression is none
  34.         0,0,0,0,  // image byte size
  35.         0x13,0x0B,0,0, // horz resoluition in pixel / m
  36.         0x13,0x0B,0,0, // vert resolutions (0x03C3 = 96 dpi, 0x0B13 = 72 dpi)
  37.         0,0,0,0,  // #colors in pallete
  38.         0,0,0,0,  // #important colors
  39. };

  40. //BMP头填充函数
  41. void CopyIntToAddress(int n, unsigned char bytes[])
  42. {
  43.         bytes[0] = n & 0xFF;
  44.         bytes[1] = (n >>  8) & 0xFF;
  45.         bytes[2] = (n >> 16) & 0xFF;
  46.         bytes[3] = (n >> 24) & 0xFF;
  47. }

  48. //主函数入口
  49. int main(int argc, char* argv[])
  50. {
  51.         if(argc!=2)
  52.         {
  53.                 fprintf(stdout, HELP_INFORMATION);
  54.                 return 1;
  55.         }

  56.         char *pCodeStr=argv[1];
  57.         CQR_Encode* pQR_Encode = new CQR_Encode;

  58.         //生成QR二维码数据
  59.         if (! pQR_Encode->EncodeData(QR_LEVEL_L, QR_VRESION_S, TRUE, -1,  pCodeStr))
  60.         {
  61.                 fprintf(stdout, "Encode data error\n");
  62.                 return 1;
  63.         }

  64.         //根据生成的QR二进制数据 建立图片的长宽
  65.         int qwith=pQR_Encode->m_nSymbleSize*BF_ZOOM+BF_MARGIN*2, qhigh=pQR_Encode->m_nSymbleSize*BF_ZOOM+BF_MARGIN*2;

  66.         int pixelWidth = qwith;
  67.         int pixelHeight = qhigh;
  68.         int rowSize = pixelWidth*3;
  69.         int rowPadding = (4-(rowSize%4))%4;
  70.         rowSize += rowPadding;
  71.         int pixelDataSize = rowSize*pixelHeight;
  72.         int fileSize = 54 + pixelDataSize;

  73.         //填充BMP头信息
  74.         CopyIntToAddress(fileSize, &header[2]);
  75.         CopyIntToAddress(pixelWidth, &header[18]);
  76.         CopyIntToAddress(pixelHeight, &header[22]);
  77.         CopyIntToAddress(pixelDataSize, &header[34]);

  78.         unsigned char* img= new unsigned char[pixelDataSize];
  79.         memset(img, 0xFF, pixelDataSize);

  80.         //遍历位图每个点
  81.         for(int i=0; i <qwith; i++)
  82.         {
  83.                 for(int j=0; j <qhigh; j++)
  84.                 {
  85.                         //如果位图中的点满足填充白色,则将该点像素值设为RGB(255,255,255)
  86.                         if(i<BF_MARGIN || i>=qwith-BF_MARGIN || j<BF_MARGIN || j>=qhigh-BF_MARGIN || !pQR_Encode->m_byModuleData[(i-BF_MARGIN)/BF_ZOOM][(j-BF_MARGIN)/BF_ZOOM])
  87.                         {

  88.                         }else{
  89.                                 int offset = (i*3)+((pixelHeight-j)-1)*rowSize;
  90.                                 img[offset  ] = (i+j)/2 + sin(i/10)*sin(j/10) *(255-(i+j)/2);
  91.                                 img[offset+1] = j + sin(j/10)*sin((i+j)/20) *(255-j);
  92.                                 img[offset+2] = i + sin((i+j)/20)* sin(i/10)*(255-i);

  93.                         }
  94.                 }
  95.         }

  96.         //保存QR图片为BMP格式
  97.         FILE* fp = fopen(qr2.bmp", "wb");
  98.         fwrite(header, 1, sizeof(header), fp);
  99.         fwrite(img, 1, pixelDataSize, fp);
  100.         fclose(fp);

  101.         //释放内存
  102.         delete pQR_Encode;
  103.         delete img;

  104.         return 0;
  105. }
复制代码
源码不依赖任何操作系统,可在linux、arm安卓、windows等各操作系统下编译运行。鉴于彩色二维码还在试验阶段,技术尚不成熟。如果识别率不佳,请自行修改RGB颜色配比关系,就能提高识别率。如果RGB的值都设置为255,就是标准黑白二维码。
发表于 2017-5-16 09:27:41 | 显示全部楼层
我弄了下不能用,安卓共享文件生成二维码还是不错的,手机在内网,开的各种共享只要别的手机一扫手机屏幕,文件就直接下了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-17 01:13 , Processed in 0.018140 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

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