ZBar 有个问题,对于中文二维码的支持经常出现乱码。ZBar 缺省支持 SHIF-JIS, UTF-8, ISO8859-1 ,但是不支持 GB18030,而很多生成的二维码都是 GB18030 (或者 GBK, GB2312)的,所以 ZBar 解码出来就直接乱码了
这个修改其实很简单,只需要修改一个文件就可以了,见下面代码。
int
qr_code_data_list_extract_text
(
const
qr_code_data_list
*_qrlist
,
zbar_image_scanner_t
*iscn
,
zbar_image_t
*img
)
{
iconv_t
sjis_cd
;
iconv_t
utf8_cd
;
iconv_t
latin1_cd
;
const
qr_code_data
*qrdata
;
int
nqrdata
;
unsigned
char
*mark
;
int
ntext
;
int
i
;
qrdata
=
_qrlist
->
qrdata
;
nqrdata
=
_qrlist
->
nqrdata
;
mark
=
(
unsigned
char
*
)
calloc
(
nqrdata
,
sizeof
(
*mark
)
)
;
ntext
=
0
;
/*This is the encoding the standard says is the default.*/
// 重点在这里,我们不要 ISO8859-1,直接换成 GB18030 就可以了
//latin1_cd=iconv_open("UTF-8","ISO8859-1");
latin1_cd=iconv_open("UTF-8","GB18030");
/*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"
)
;
|
http://blog.csdn.net/nextj/article/details/8088759