示例#1
0
        public void GenerateBitmap(string toEncode, string testFile)
        {
            // Arrange
            const double scale    = 1D;
            var          settings = GetPdf417Settings(50, 6, 2, 1);

            // Act
            using (IBarcode barcode = new BC.Pdf417())
            {
                using var bmp  = barcode.Encode(toEncode, settings);
                using var bmp2 = new Bitmap((int)(bmp.Width * scale), (int)(bmp.Height * scale));
                using (var gfx = Graphics.FromImage(bmp2))
                {
                    gfx.DrawImage(bmp, new Rectangle(0, 0, bmp2.Width, bmp2.Height));
                }
                bmp2.Save(testFile, ImageFormat.Png);
            }

            //Assert
            FileAssert.Exists(testFile);
        }
示例#2
0
        public void TestUTF8Barcode(string toEncode, string testFile)
        {
            // Arrange
            const double scale    = 1D;
            var          settings = GetPdf417Settings(3, 5, 2, 1);

            // Act
            using (IBarcode barcode = new BC.Pdf417())
            {
                // This is where the trick lies. Problem is that readers should decode to UTF8, too
                var bytes = Encoding.UTF8.GetBytes(toEncode);

                using var bmp  = barcode.Encode(bytes, settings);
                using var bmp2 = new Bitmap((int)(bmp.Width * scale), (int)(bmp.Height * scale));
                using (var gfx = Graphics.FromImage(bmp2))
                {
                    gfx.DrawImage(bmp, new Rectangle(0, 0, bmp2.Width, bmp2.Height));
                }
                bmp2.Save(testFile, ImageFormat.Png);
            }

            //Assert
            FileAssert.Exists(testFile);
        }
示例#3
0
        public void GeneratePrintableHtml(string toEncode, string testFile)
        {
            // Arrange
            var settings = GetPdf417Settings(20, 15, 2, 1);

            settings.ImageFormat = ImageFormat.Png;

            // Act
            using (IBarcode barcode = new BC.Pdf417())
            {
                var b   = Convert.ToBase64String(barcode.EncodeToBytes(toEncode, settings));
                var doc = new XDocument(
                    new XElement("html",
                                 new XElement("body",
                                              new XElement("img", new XAttribute("src", $"data:image/png;base64,{b}"))
                                              )
                                 )
                    );
                doc.Save(testFile);
            }

            //Assert
            FileAssert.Exists(testFile);
        }
示例#4
0
        public void TestBase64Barcode(string toEncodeBase64, string testFile)
        {
            // Arrange
            const double scale    = 1D;
            var          name     = Convert.ToBase64String(Encoding.UTF8.GetBytes("AYŞEAYŞE"));
            var          surname  = Convert.ToBase64String(Encoding.UTF8.GetBytes("AYŞEEŞYAAYŞEEŞYA"));
            var          toEncode = string.Format(toEncodeBase64, name, surname);
            var          settings = GetPdf417Settings(20, 15, 2, 1);

            // Act
            using (IBarcode barcode = new BC.Pdf417())
            {
                using var bmp  = barcode.Encode(toEncode, settings);
                using var bmp2 = new Bitmap((int)(bmp.Width * scale), (int)(bmp.Height * scale));
                using (var gfx = Graphics.FromImage(bmp2))
                {
                    gfx.DrawImage(bmp, new Rectangle(0, 0, bmp2.Width, bmp2.Height));
                }
                bmp2.Save(testFile, ImageFormat.Png);
            }

            //Assert
            FileAssert.Exists(testFile);
        }