Spire.Barcode is a professional barcode library specially designed for .NET developers (C#, VB.NET, ASP.NET, .NET Core) and Java developers (J2SE and J2EE) to generate, read and scan 1D & 2D barcodes.

Fri Jan 24, 2014 10:06 am

When encoding string like for example "ščťž", I get a DataMatrix code as output (unlike other libraries which produce error in this case), but I am not sure how the result is produced and what exactly comes into the code (do not have the reader yet).

Is there an automatic base64 conversion to fit into ascii or how exactly are these non-ASCII characters encoded in DataMatrix?

mako
 
Posts: 2
Joined: Fri Jan 24, 2014 10:01 am

Sun Jan 26, 2014 9:12 am

Hello mako,
Thank you for your inquiry. Please check the code below:
Code: Select all
private void button1_Click(object sender, EventArgs e)
        {
            IBarcodeSettings barSetting = new BarcodeSettings();
            barSetting.Type = BarCodeType.DataMatrix;
            barSetting.Data = GetEncodingText("ščťž");
            barSetting.Data2D = GetEncodingText("ščťž");
            BarCodeGenerator bar = new BarCodeGenerator(barSetting);
            bar.GenerateImage().Save(@"d:\test.bmp");
        }

        public string GetEncodingText(string unicodeStr)
        {
            string encodingResult = "";
            byte[] byteArray = Encoding.Unicode.GetBytes(unicodeStr);
            foreach (byte b in byteArray)
                encodingResult += (char)b;
            return encodingResult;
        }


        public string GetDecodingText(string unicodeStr)
        {
            string decodingResult = "";
            List<byte> bytes = new List<byte>();
            foreach (char c in unicodeStr)
                bytes.Add((byte)c);
            decodingResult = Encoding.Unicode.GetString(bytes.ToArray());
            return decodingResult;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string barResult = BarcodeScanner.ScanOne(@"d:\test.bmp");
            System.Diagnostics.Debug.WriteLine(GetDecodingText(barResult));
        }

If you have any questions, welcome to get it back to us.

Regards,
Benjamin
E-iceblue support team
User avatar

Benjamin Du
 
Posts: 82
Joined: Thu Jul 25, 2013 2:38 am

Mon Jan 27, 2014 7:27 am

HI Benjamin,

thank you for your answer. It is clear to me how to produce the output using your library. My question is about how non-ASCII character encoding is implemented inside the BarCode library, since DataMatrix specifies that only ASCII characters can be encoded, unless Base256 mode is being used, or the string is converted into base64. Which of the options is Spire.BarCode using?

mako
 
Posts: 2
Joined: Fri Jan 24, 2014 10:01 am

Mon Jan 27, 2014 8:40 am

Hello mako,

It is my pleasure to help you.
Only ASCII character is supported inside our BarCode library. If you want to deal with non-ASCII character encoding, please refer this:
(1) Non-ASCII character must be converted to ASCII character encoding.
(2) Use the ASCII character from (1) to generate DataMatrix barcode.
This is how to generate DataMatrix barcode. When scanning barcode images, just reverse the process.

If you have any questions, welcome to tell to us.

Regards,
Benjamin
E-iceblue support team
User avatar

Benjamin Du
 
Posts: 82
Joined: Thu Jul 25, 2013 2:38 am

Return to Spire.BarCode