2013-09-23 76 views
1

我正在使用libqrencode
我想要一個QR碼版本1(21x21)和ECC等級H。根據http://www.qrcode.com/en/about/version.html我可以有17個數字。所以我這樣做:如何正確編碼數字QRCode?

QRcode *result; 
QRinput *input = QRinput_new2(1, QR_ECLEVEL_H); 
unsigned char *data = new unsigned char[17]; 
for(int i = 0; i < 17; i++) { 
    data[i] = 0; 
} 

QRinput_append(input, QR_MODE_NUM, 17, data); 

result = QRcode_encodeInput(input); 

int idx = 0; 
printf("%d\n", result->width); 
for(int i = 0; i < result->width; i++) { 
    for(int j = 0; j < result->width; j++) { 
     if(result->data[idx] & 1) { 
      printf("%d", 1); 
     } else { 
      printf("%d", 0); 
     } 
     idx++; 
    } 
    printf("\n"); 
} 

但whaterver我的數據是,我的程序返回相同的輸出。
我在這裏錯過了什麼?

回答

0

我提出一個問題,因爲有github上,並得到了答案很快https://github.com/fukuchi/libqrencode/issues/33#issuecomment-24997167
的問題是我的數據初始化這裏:

unsigned char *data = new unsigned char[17]; 
for(int i = 0; i < 17; i++) { 
    data[i] = 0; 
} 

應該是:

unsigned char *data = new unsigned char[17]; 
for(int i = 0; i < 17; i++) { 
    data[i] = '0'; //here 
}