Help with Shift_JIS QR encoding in the Zxing Code Generator Page

505 views
Skip to first unread message

Eddie

unread,
Dec 13, 2011, 3:07:50 PM12/13/11
to zxing
I'm trying to encode with Shift_JIS but my qr code does not match the
output shown by the Zxing Code Generator Page (http://
zxing.appspot.com/generator/).

The test string is:
1234567890お客様名ABCDEabcdeアイウエオ鰺鯵

My code looks like this:

QRCode qrcode = new QRCode();
Hashtable<EncodeHintType, String> hints = new
Hashtable<EncodeHintType, String>(2);
hints.put(EncodeHintType.CHARACTER_SET, "Shift_JIS");
Encoder.encode(contents, ecLevel, hints, qrcode);

My result matches the UTF-8 qr code generated on the generator page
instead of the Shift_JIS qr code.

I've tried encoding the string to Shift_JIS before the Encoder.encode
call but that results in the same UTF-8 qr code.

Sean Owen

unread,
Dec 13, 2011, 3:13:31 PM12/13/11
to zx...@googlegroups.com
I don't think you can select encoding on the Google Chart Server URL, so I believe it will just default to UTF-8. Even if you could you'd have to make sure your input encoding was specified, your payload correctly encoded, and set the output encoding to 'sjis'. Don't know if you can do that. So, the one you are getting from zxing.appspot.com/generator is not what you want.

Your code above is correct though.

Eddie

unread,
Dec 13, 2011, 3:18:32 PM12/13/11
to zxing
Hi Sean, actually the zxing.appspot.com/generator is giving me the
result that I want, it matches the Shift_JIS result for the same
string from http://www.racoindustries.com/barcodegenerator/2d/qr-code.aspx

Sean Owen

unread,
Dec 13, 2011, 4:21:03 PM12/13/11
to zx...@googlegroups.com
Nope, the generator creates this image:


If you decode the resulting image and step through, you'll find the text is UTF-8 encoded. The other site is also generating UTF-8 I imagine.

But, good news. See the "choe=UTF-8" parameter? I didn't recall that this existed. Just change it to "sjis" and it will output a code containing the same text in Shift_JIS encoding.

The good news is that the default *input* encoding it assumes is UTF-8, and that is how your browser defaults to encode these characters as %XX values. (This is by the way nonstandard.) I assume that's the same reason you're getting UTF-8 out of the other system.

Eddie Greene

unread,
Dec 13, 2011, 4:37:37 PM12/13/11
to zx...@googlegroups.com
Thanks for your help Sean, I see what you are saying about the encoding parameter in the url. I might be miscommunicating my problem though.

What I'd like to generate in Java code is this output:
http://chart.apis.google.com/chart?cht=qr&chs=350x350&chld=H&choe=Shift_JIS&chl=1234567890%E3%81%8A%E5%AE%A2%E6%A7%98%E5%90%8DABCDEabcde%EF%BD%B1%EF%BD%B2%EF%BD%B3%EF%BD%B4%EF%BD%B5%E9%B0%BA%E9%AF%B5

However, even with my hints indicating Shift_JIS, I always get this output:
http://chart.apis.google.com/chart?cht=qr&chs=350x350&chld=H&choe=UTF-8&chl=1234567890%E3%81%8A%E5%AE%A2%E6%A7%98%E5%90%8DABCDEabcde%EF%BD%B1%EF%BD%B2%EF%BD%B3%EF%BD%B4%EF%BD%B5%E9%B0%BA%E9%AF%B5

As you pointed out, the choe=UTF-8 is what I'm seeing, my code is giving me UTF-8 dispite my hints indicating that I'd like Shift_JIS.

So it seems that I cannot get the Java code to set the Mode.KANJI, it sees the first character as a 1 and then makes it Mode.BYTE. I was wondering how the Zxing qr generator got around this to make the qr in Shift_JIS.

Sean Owen

unread,
Dec 13, 2011, 5:47:12 PM12/13/11
to zx...@googlegroups.com
It's "sjis" not "Shift_JIS" for the Google Chart Server. Your first link has an invalid encoding and so it defaults to UTF-8, so both images are the same.

This is nothing to do with the Java code. Your Java code looks right -- if you want Shift-JIS.

This is also nothing to do with Kanji mode. I thought you wanted byte mode with Shift-JIS encoding?

Eddie

unread,
Dec 13, 2011, 6:15:07 PM12/13/11
to zxing
Hi Sean,

About the qr codes being the same, I think they will decode the same,
but they are not the same. Visually they are different, and the UTF-8
version does not decode on Docomo iMode cell phones.

About Modes, I'm not sure if I understand the Zxing Mode very well, I
assumed that Mode.KANJI was for all Shift_JIS/sjis encoding.

Sean Owen

unread,
Dec 13, 2011, 6:56:08 PM12/13/11
to zx...@googlegroups.com
Oops you are right, I think I clicked the same link twice. They are definitely different since the bytes are different.

Kanji mode is not the same as byte mode with Shift-JIS encoding, no.

Eddie

unread,
Jan 4, 2012, 2:29:37 PM1/4/12
to zxing
I found that to produce a Qr Code that works with DoCoMo Imode phones
I needed to change the encoding to "x-sjis" instead of "Shift_JIS".
Reply all
Reply to author
Forward
0 new messages