0

So, I have a block of text in which there is a barcode. For this I use the Code128 font to display text as a barcode. But it doesn't work that easy with Code 128. So I took the following Encode in the hope that my text would be changed into a scannable barcode. however for some reason i still can't read it.

 public string BarcodeEncode(string value)
    {
        int[] overChars = { 8216, 8217, 8220, 8221, 8226, 8211, 8212, 732, 8364 };
        char[] valueChars = value.ToCharArray();
        int[] checksumVals = new int[value.Length];

        for (int n = 0; n < valueChars.Length; n++)
        {
            checksumVals[n] = (((byte)valueChars[n]) - 32) * (n + 1);
        }

        int checksum = checksumVals.Sum() % 103;
        char check = (char)(checksum + 33);
        if (checksum > 93)
            check = (char)overChars[checksum - 94];

        string start = ((char)353).ToString();
        string stop = ((char)339).ToString();

        return start + value + check.ToString() + stop;
    }

Bevor this decoding my BarCode lookslike that:

Before

But I cant scan it with an barcode scanner.

So I did the following method, in the hope that with this change I will be able to scan the barcode with a Bacode scanner.

But after that my Barcode looks like that:

Barcode2

And it doesnt work either

The Input of my Barcode is just a text "Hellooo" nothing special yet

Klaus Gütter
  • 11,151
  • 6
  • 31
  • 36
  • 1
    If I get it right, this code calculates a checksum and then produces a result by concatenation. It it that your checkum is not correct? or what does "I cannot read it" mean? Please give some sample input, the expected and the observed output. – Klaus Gütter Dec 15 '21 at 13:34
  • I editet the Question, may that will help you better to understand my Problem –  Dec 15 '21 at 15:14
  • Code-128 isn't just a "one character, one line pattern" code, you need to *encode* your value first, and how to encode that value depends on the particular font used. If you need a barcode where you can just output an arbitrary string with a font and be done, use 3of9 instead (google for Free3of9 for one such font). – Heinzi Dec 15 '21 at 15:17

0 Answers0