标题: 彩色二维码生成工具qr2.exe [打印本页]
作者: happy886rr 时间: 2017-5-14 22:35 标题: 彩色二维码生成工具qr2.exe
本帖最后由 happy886rr 于 2017-5-14 22:53 编辑
下载:存图片为a.zip,解压即是。(全部外链,另笔名正式由HAPPY改为LEO,以便统一不同论坛作品笔名)
QR2.EXE是一款C语言写的彩色二维码生成器,可以生成色彩斑斓的彩色码块,虽然识别效率有所下降,但微信,QQ等工具识别还是蛮快的。
编码算法借助日本QR编码规则https://github.com/lys861205/qrC ... rTest/QR_Encode.cpp。核心色彩转化代码如下:- /*
- CONSOLE QRCODE, COPYRIGHT@2017~2019 BY LEO, VERSION 1.0
- QR2.EXE
- */
- #include <stdio.h>
- #include <math.h>
- #include <stdlib.h>
- #include <string.h>
- #include "QR_Encode.cpp"
-
- #define BF_ZOOM 10
- #define BF_MARGIN 10
-
- //定义帮助说明
- #define HELP_INFORMATION "\
- QR2 version 1.0 - Console qrcode tool - Copyright (C) 2017-2019 by Leo\n\
- \n\
- Usage:\n\
- qr2 [your text]\n\
- \n\
- Official website:\n\
- http://www.bathome.net/thread-44143-1-1.html\n"
-
- //定义BMP头
- static unsigned char header[] =
- {
- 'B','M', // magic number
- 0,0,0,0, // size in bytes (set below)
- 0,0,0,0, // reserved
- 54,0,0,0, // offset to start of pixel data
- 40,0,0,0, // info hd size
- 0,0,0,0, // image width (set below)
- 0,0,0,0, // image heigth (set below)
- 1,0, // number color planes
- 24,0, // bits per pixel
- 0,0,0,0, // compression is none
- 0,0,0,0, // image byte size
- 0x13,0x0B,0,0, // horz resoluition in pixel / m
- 0x13,0x0B,0,0, // vert resolutions (0x03C3 = 96 dpi, 0x0B13 = 72 dpi)
- 0,0,0,0, // #colors in pallete
- 0,0,0,0, // #important colors
- };
-
- //BMP头填充函数
- void CopyIntToAddress(int n, unsigned char bytes[])
- {
- bytes[0] = n & 0xFF;
- bytes[1] = (n >> 8) & 0xFF;
- bytes[2] = (n >> 16) & 0xFF;
- bytes[3] = (n >> 24) & 0xFF;
- }
-
- //主函数入口
- int main(int argc, char* argv[])
- {
- if(argc!=2)
- {
- fprintf(stdout, HELP_INFORMATION);
- return 1;
- }
-
- char *pCodeStr=argv[1];
- CQR_Encode* pQR_Encode = new CQR_Encode;
-
- //生成QR二维码数据
- if (! pQR_Encode->EncodeData(QR_LEVEL_L, QR_VRESION_S, TRUE, -1, pCodeStr))
- {
- fprintf(stdout, "Encode data error\n");
- return 1;
- }
-
- //根据生成的QR二进制数据 建立图片的长宽
- int qwith=pQR_Encode->m_nSymbleSize*BF_ZOOM+BF_MARGIN*2, qhigh=pQR_Encode->m_nSymbleSize*BF_ZOOM+BF_MARGIN*2;
-
- int pixelWidth = qwith;
- int pixelHeight = qhigh;
- int rowSize = pixelWidth*3;
- int rowPadding = (4-(rowSize%4))%4;
- rowSize += rowPadding;
- int pixelDataSize = rowSize*pixelHeight;
- int fileSize = 54 + pixelDataSize;
-
- //填充BMP头信息
- CopyIntToAddress(fileSize, &header[2]);
- CopyIntToAddress(pixelWidth, &header[18]);
- CopyIntToAddress(pixelHeight, &header[22]);
- CopyIntToAddress(pixelDataSize, &header[34]);
-
- unsigned char* img= new unsigned char[pixelDataSize];
- memset(img, 0xFF, pixelDataSize);
-
- //遍历位图每个点
- for(int i=0; i <qwith; i++)
- {
- for(int j=0; j <qhigh; j++)
- {
- //如果位图中的点满足填充白色,则将该点像素值设为RGB(255,255,255)
- 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])
- {
-
- }else{
- int offset = (i*3)+((pixelHeight-j)-1)*rowSize;
- img[offset ] = (i+j)/2 + sin(i/10)*sin(j/10) *(255-(i+j)/2);
- img[offset+1] = j + sin(j/10)*sin((i+j)/20) *(255-j);
- img[offset+2] = i + sin((i+j)/20)* sin(i/10)*(255-i);
-
- }
- }
- }
-
- //保存QR图片为BMP格式
- FILE* fp = fopen(qr2.bmp", "wb");
- fwrite(header, 1, sizeof(header), fp);
- fwrite(img, 1, pixelDataSize, fp);
- fclose(fp);
-
- //释放内存
- delete pQR_Encode;
- delete img;
-
- return 0;
- }
复制代码
源码不依赖任何操作系统,可在linux、arm安卓、windows等各操作系统下编译运行。鉴于彩色二维码还在试验阶段,技术尚不成熟。如果识别率不佳,请自行修改RGB颜色配比关系,就能提高识别率。如果RGB的值都设置为255,就是标准黑白二维码。
作者: 3518228042 时间: 2017-5-16 09:27
我弄了下不能用,安卓共享文件生成二维码还是不错的,手机在内网,开的各种共享只要别的手机一扫手机屏幕,文件就直接下了
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |