Example #1
0
        public static byte[] GenerateEanThirteen(string eanThirteenCode, int width, int height)
        {
            EAN13Writer writer = new EAN13Writer();

            BitMatrix matrix = writer.encode(eanThirteenCode, BarcodeFormat.EAN_13, width, height);

            return(matrix.ToPng());
        }
 public void testEncode()
 {
    String testStr = "00010100010110100111011001100100110111101001110101010110011011011001000010101110010011101000100101000";
    BitMatrix result = new EAN13Writer().encode("5901234123457", BarcodeFormat.EAN_13, testStr.Length, 0);
    for (int i = 0; i < testStr.Length; i++)
    {
       Assert.AreEqual(testStr[i] == '1', result[i, 0], "Element " + i);
    }
 }
Example #3
0
        public void testEncode()
        {
            String    testStr = "00010100010110100111011001100100110111101001110101010110011011011001000010101110010011101000100101000";
            BitMatrix result  = new EAN13Writer().encode("5901234123457", BarcodeFormat.EAN_13, testStr.Length, 0);

            for (int i = 0; i < testStr.Length; i++)
            {
                Assert.AreEqual(testStr[i] == '1', result[i, 0], "Element " + i);
            }
        }
Example #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public com.google.zxing.common.BitMatrix encode(String contents, BarcodeFormat format, int width, int height, java.util.Map<EncodeHintType,?> hints) throws WriterException
        public BitMatrix encode(string contents, BarcodeFormat format, int width, int height, IDictionary <EncodeHintType, object> hints)
        {
            Writer writer;

            switch (format)
            {
            case com.google.zxing.BarcodeFormat.EAN_8:
                writer = new EAN8Writer();
                break;

            case com.google.zxing.BarcodeFormat.EAN_13:
                writer = new EAN13Writer();
                break;

            case com.google.zxing.BarcodeFormat.UPC_A:
                writer = new UPCAWriter();
                break;

            case com.google.zxing.BarcodeFormat.QR_CODE:
                writer = new QRCodeWriter();
                break;

            case com.google.zxing.BarcodeFormat.CODE_39:
                writer = new Code39Writer();
                break;

            case com.google.zxing.BarcodeFormat.CODE_128:
                writer = new Code128Writer();
                break;

            case com.google.zxing.BarcodeFormat.ITF:
                writer = new ITFWriter();
                break;

            case com.google.zxing.BarcodeFormat.PDF_417:
                writer = new PDF417Writer();
                break;

            case com.google.zxing.BarcodeFormat.CODABAR:
                writer = new CodaBarWriter();
                break;

            default:
                throw new System.ArgumentException("No encoder available for format " + format);
            }
            return(writer.encode(contents, format, width, height, hints));
        }
Example #5
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));
            }
        }
        public void testEncode(string content, string encoding)
        {
            var result = new EAN13Writer().encode(content, BarcodeFormat.EAN_13, encoding.Length, 0);

            Assert.AreEqual(encoding, BitMatrixTestCase.matrixToString(result));
        }