简体   繁体   English

[zbar]ZBar如何解码包含中文(utf-8)的二维码?

[英][zbar]How to decode qr code which contains Chinese (utf-8) by ZBar?

I am using libZbar,it decode QR code is fast when i decode which QR is contained Chinese(GBK Character),but when decoding the QR which contains Chinese(UTF-8),it will return err language.我正在使用libZbar,当我解码包含中文(GBK字符)的QR时,它解码QR码很快,但是当解码包含中文(UTF-8)的QR时,它会返回错误的语言。 enter image description here在此处输入图像描述

This is QR content "墨水好多EXij-/?:;,AEyv0008"?but when i used libZbar to decode it shows"蠅ィ豌エ螂ス螟哘Xij-/:;..AEyv0008" i found the"EXij..."->"Xij.,," and then.i check some ways to deal with this problem.I checked libZbar source code /zbar-0,10/zbar/qrcode/qrdectxt,c,they saies change this code ISO8859-1 -> GB18030 or GB2312 ,but it can`t help me这是“墨水多种EXij-?:;,0008”?但是当我用libZbar解码时显示“昆虫ィQR内容エ蟑螂~哽Xij-/:;..AEyv0008”我找到了“EXij” .."->"Xij.,," 然后。我检查了一些方法来处理这个问题。我检查了 libZbar 源代码 /zbar-0,10/zbar/qrcode/qrdectxt,c,他们说更改此代码 ISO8859 -1 -> GB18030 或 GB2312,但它帮不了我

/*This is the encoding the standard says is the default.*/   
        latin1_cd=iconv_open("UTF-8","ISO8859-1"); 
/*But this one is often used, as well.*/
         sjis_cd=iconv_open("UTF-8","SJIS"); 
/*This is a trivial conversion just to check validity without extra code.*/   
        utf8_cd=iconv_open("UTF-8","UTF-8");

My program is coding by Qt runing on linux,the normal Chinese(utf-8) is show well, The Zbar has converted the content of utf8 encoding into other encoding formats.我的程序是Qt在linux上运行的编码,正常的中文(utf-8)显示很好,Zbar已经将utf8编码的内容转换为其他编码格式。 This is not the step I need, but I cannot comment this entire code.这不是我需要的步骤,但我无法评论整个代码。 What can I do?我能做些什么?

  1. Modify this part of the code, but I don't quite understand where to modify this part of the code.修改这部分代码,但是我不太明白在哪里修改这部分代码。

  2. Convert the character after zbar conversion back to utf8, I tried it, iconv() call failed and return -1.将zbar转换后的字符转回utf8,我试了一下,iconv()调用失败,返回-1。

    int ret =0; int ret = 0; iconv_t cd; iconv_t 光盘; cd = iconv_open("sjis","utf-8");//or ISO8859-1 to utf-8 cd = iconv_open("sjis","utf-8");//或 ISO8859-1 到 utf-8
    ret = iconv(cd, &input, &charInPutLen, &output, &charOutPutLen); ret = iconv(cd, &input, &charInPutLen, &output, &charOutPutLen); iconv_close(cd); iconv_close(cd); the zbar source code function:qr_code_data_list_extract_text in line 45 zbar 源代码 function:qr_code_data_list_extract_text 在第 45 行

enter link description here 在此处输入链接描述

i build a c project with Qt,then a debug it by step.this qr code does not contain utf8 flag begin in head,so it will use enc_list to deal with text, just change index of enc_list[] utf8_cd -> first我用 Qt 构建了一个 c 项目,然后逐步调试它。这个二维码不包含开头的 utf8 标志,所以它将使用 enc_list 处理文本,只需更改 enc_list[] utf8_cd 的索引 -> 首先

enc_list[2]=sjis_cd; enc_list[1]=latin1_cd; enc_list[0]=utf8_cd;

 if(inleft>=3&&in[0]==(char)0xEF&&in[1]==(char)0xBB&&in[2]==(char)0xBF)
 {
                in+=3;
                inleft-=3;
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM