public void Should_Encode(string contents)
        {
            var sut       = new Code128Writer();
            var sutDecode = new Code128Reader();

            var result       = sut.encode(contents, BarcodeFormat.CODE_128, 0, 0);
            var resultString = BitMatrixTestCase.matrixToString(result);

            Console.WriteLine(contents);
            Console.WriteLine(resultString);
            Console.WriteLine("");
            var matrix = BitMatrix.parse(resultString, "1", "0");
            var row    = new BitArray(matrix.Width);

            matrix.getRow(0, row);
            var decodingResult = sutDecode.decodeRow(0, row, null);

            Assert.That(decodingResult, Is.Not.Null);
            Assert.That(decodingResult.Text, Is.EqualTo(contents));
        }
Esempio n. 2
0
        public static Bitmap DrawBarCode(string data, BarcodeFormat format, int width, int height)
        {
            BitMatrix bm;

            try
            {
                switch (format)
                {
                case BarcodeFormat.UPC_A:
                    UPCAWriter writer = new UPCAWriter();
                    bm = writer.encode(data, format, width, height);
                    break;

                case BarcodeFormat.UPC_E:
                    UPCEWriter upcew = new UPCEWriter();
                    bm = upcew.encode(data, format, width, height);
                    break;

                case BarcodeFormat.EAN_8:
                    EAN8Writer ean8w = new EAN8Writer();
                    bm = ean8w.encode(data, format, width, height);
                    break;

                case BarcodeFormat.EAN_13:
                    EAN13Writer ean13w = new EAN13Writer();
                    bm = ean13w.encode(data, format, width, height);
                    break;

                case BarcodeFormat.CODE_39:
                    Code39Writer c39w = new Code39Writer();
                    bm = c39w.encode(data, format, width, height);
                    break;

                case BarcodeFormat.ITF:
                    ITFWriter iw = new ITFWriter();
                    bm = iw.encode(data, format, width, height);
                    break;

                case BarcodeFormat.CODABAR:
                    CodaBarWriter cbw = new CodaBarWriter();
                    bm = cbw.encode(data, format, width, height);
                    break;

                case BarcodeFormat.CODE_93:
                    Code93Writer c93w = new Code93Writer();
                    bm = c93w.encode(data, format, width, height);
                    break;

                case BarcodeFormat.CODE_128:
                    Code128Writer c128w = new Code128Writer();
                    bm = c128w.encode(data, format, width, height);
                    break;

                default:
                    return(null);
                }
                BarcodeWriter bw = new BarcodeWriter();
                return(bw.Write(bm));
            }
            catch
            {
                return(new Bitmap(10, 10));
            }
        }