c++生成二維碼

Dsp Tian發表於2017-08-27

vs2010編譯好的qrencode庫:http://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,[])

相關文章