Beispiel #1
0
        public static void Main()
        {
            var encoder = new BarcodeEncoder();
            var reader  = new BarcodeReader {
                Options = { PossibleFormats = new[] { BarcodeFormat.CODE_128 } }
            };

            var count = 0;

            foreach (var text in CreateTexts(25, 4000))
            {
                if (!encoder.TryEncode(text, out var codes))
                {
                    throw new Exception("Failed to encode " + text);
                }

                var barcode = new BarcodePainter(codes);
                using (var bitmap = barcode.Draw(3, 42))
                {
                    var decoded = reader.Decode(bitmap);
                    if (decoded.Text != text)
                    {
                        throw new Exception("Encoded " + text + " but read " + decoded.Text);
                    }
                }

                Console.Write($"\rTested {++count} codes");
            }

            Console.WriteLine();
        }
Beispiel #2
0
        public static void Main(string[] args)
        {
            var text = args.Length > 0 ? args[0] : "test";

            if (BarcodeEncoder.TryEncodeBarcode(text, out var codes))
            {
                using (var bitmap = BarcodePainter.Draw(codes, 1, 20))
                {
                    bitmap.Save("output.png", ImageFormat.Png);
                }
            }
            else
            {
                throw new Exception($"The text {text} contains unsupported characters.");
            }
        }