c++生成二维码
vs2010编译好的qrencode库:https://files.cnblogs.com/files/verstin/qrencode.rar
版本是3.4.4
编译方法参考:http://blog.csdn.net/liyuanbhu/article/details/44647139
测试代码:
#include <iostream> #include "qrencode.h" using namespace std; int main(int argc, char *argv[]) { QRcode *qr = QRcode_encodeString("http://www.cnblogs.com/tiandsp/", 1, QR_ECLEVEL_L, QR_MODE_8, 1); int width = qr->width; int height = width; FILE *fp = fopen("out.txt", "w"); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if (qr->data[y*width + x] & 0x01) { fprintf(fp, "0 "); } else { fprintf(fp, "1 "); } } fprintf(fp, "\n"); } fclose(fp); QRcode_free(qr); }
输出out.txt,然后我们在matlab中把二维码画出来:
matlab代码:
a=load('out.txt'); b=zeros(400,400); for i=1:25 for j=1:25 if a(i,j)==1 b(16*(i-1)+1:16*(i),16*(j-1)+1:16*(j))=1; end end end imshow(b,[])