Introduction
The modern Japanese writing system uses Kanji and Kana symbols. As a symbology developed in Japan, QR Code (and Micro QR) is capable of efficiently encoding these symbols. We have the sample "KanjiKanaEncodeDecode" in our ZIP package showing how you can easily encode and decode such data.
For most barcode types, to encode data we use the BarcodeValue property of the Writer class and to decode data we use the BarcodeValue property of the Result class. To work with Kanji/Kana, and in general with any binary data in bytes, we use the BarcodeData property of the Writer class and the BarcodeDataAsByte property of the Result class respectively.
How to Encode/Decode Data With Kanji/Kana Symbols in QR Barcodes
To create a QR barcode with a Kanji string, first we encode this string into a byte array using appropriate character encoding. By default, Shift JIS (Shift Japanese Industrial Standards, also SJIS or Shift_JIS) character encoding is used for Kanji and Kana. Reading a QR barcode with Kanji is a reverse operation. After getting a result as a byte array from Barcode Xpress, we decode it using the same character encoding which was used for barcode creation. Barcode Xpress does not not know what type of encoding is supposed to be used for the data. Determining the correct encoding is the responsibility of the application.
Here are two C# examples:
Example - Basic steps to create a QR Code with Kanji/Kana
using (BarcodeXpress barcodeXpress = new BarcodeXpress("."))
{
// Create a QR Code with a barcode value containing Kanji symbols.
using (WriterQRCode qrWriter = new WriterQRCode(barcodeXpress))
{
// Encode Kanji/Kana string into a sequence of bytes and use BarcodeData property to create a barcode with binary data.
qrWriter.BarcodeData = Encoding.GetEncoding("Shift_JIS").GetBytes("漢字 string");
using (Bitmap qrBitmap = qrWriter.CreateBitmap())
{
// Save the created bitmap to a local file.
qrBitmap.Save("qrBarcode.bmp", ImageFormat.Bmp);
}
}
}
Example - Basic steps to read a QR Code with Kanji/Kana
using (BarcodeXpress barcodeXpress = new BarcodeXpress("."))
{
using (Bitmap bitmap = new Bitmap("qrBarcode.bmp"))
{
// Set the type of barcodes to analyze during recognition processing.
barcodeXpress.reader.BarcodeTypes = new BarcodeType[] { BarcodeType.QRCodeBarcode };
// Detect barcodes on the given bitmap image.
Accusoft.BarcodeXpressSdk.Result[] results = barcodeXpress.reader.Analyze(bitmap);
for (int i = 0; i < results.Length; i++)
{
// Use BarcodeDataAsByte property to get the recognized barcode data value in bytes and decode it.
// Note: Barcode Xpress does not not know what type of encoding is supposed to be used for the data.
// Determining the correct encoding is the responsibility of the application.
Console.WriteLine("Barcode value: {0}", Encoding.GetEncoding("Shift_JIS").GetString(results[0].BarcodeDataAsByte));
}
}
}