示例#1
0
        private static byte[] CreateEmfBytes(string contents, QREncodeMode mode, QRErrorLevel errorLevel)
        {
            var builder  = CreateQrBuilder(contents, mode, errorLevel);
            var emfImage = new MemoryStream();

            builder.SaveAsEmf(emfImage);
            return(emfImage.ToArray());
        }
示例#2
0
        public void CheckRandomCharWithPattern(QRErrorLevel errLevel)
        {
            Trace.WriteLine(errLevel);
            var    watch       = System.Diagnostics.Stopwatch.StartNew();
            int    numSuccess  = 0;
            int    numFails    = 0;
            int    sampleFail  = 0;
            double successRate = 0;
            double elapsedMs   = 0;

            for (int i = 999; i >= 0; i--)
            {
                string str = "";
                try
                {
                    var    mandant   = FakerRandom.Rand.Next(999);
                    int    anzSeiten = FakerRandom.Rand.Next(99);
                    var    numSeite  = FakerRandom.Rand.Next(anzSeiten);
                    string codGoTyp  = Lorem.GetWord();
                    string codGoNr   = Lorem.GetWord();
                    int    codHuelle = FakerRandom.Rand.Next(9999);
                    str = $"SAMDMS: MANDANT ={mandant}; NUMSEITE = {numSeite}; ANZSEITEN ={anzSeiten}; ABLAGE = (COD_GO_TYP = {codGoTyp}; COD_GO_NR ={codGoNr};COD_HUELLE ={codHuelle})";
                    var bmp = QrCode.Create(str, errLevel);
                    bmp.Save("TestRandomCharWithPattern.bmp", ImageFormat.Bmp);
                    var emf = QrCode.CreateEmf(str, QREncodeMode.Binary, QRErrorLevel.LevelM);
                    emf.Save("TestRandomCharWithPattern.emf", ImageFormat.Emf);
                    var result = QrCode.ReadAsString(bmp);
                    Assert.AreEqual(str, result);
                    numSuccess++;
                }
                catch (System.Exception x)
                {
                    numFails++;
                    if (sampleFail == 0)
                    {
                        Trace.WriteLine(message: $"{x.Message} with this Input: \n{str}");
                    }
                    sampleFail = 1;
                }
            }
            successRate = System.Math.Round((double)numSuccess / (numSuccess + numFails) * 100, 2);
            Trace.WriteLine("Success: " + numSuccess + ", Fail: " + numFails);
            Trace.WriteLine("Successrate: " + successRate + "%");
            watch.Stop();

            elapsedMs = watch.ElapsedMilliseconds / 1000;
            Trace.WriteLine("Elapsed Time: " + elapsedMs);
            Trace.WriteLine("");
        }
示例#3
0
        /// <summary> Allowed <paramref name="resolution"/> are  </summary>
        private static Bitmap CreateBitmap(string contents
                                           , int?resolution          = null, QREncodeMode mode = DefaultQrEncodeMode
                                           , QRErrorLevel errorLevel = DefaultQrErrorLevel)
        {
            Bitmap bitmap = CreateBitmapImage(contents, resolution, mode, errorLevel);

            return(bitmap);

            /*using (var ms = new MemoryStream())
             * {
             *  bitmap.Save(ms, ImageFormat.Png);
             *  var content = ms.ToArray();
             *  return CreateImage(content);
             *  //return new Image(content, "QR.png");
             * }*/
        }
示例#4
0
 public static Image CreateEmf(string contents, QREncodeMode mode, QRErrorLevel errorLevel)
 => CreateImage(CreateEmfBytes(contents, mode, errorLevel));
示例#5
0
 public static Bitmap Create(string contents, int resolution, QREncodeMode mode, QRErrorLevel errorLevel)
 => CreateBitmap(contents, resolution, mode, errorLevel);
示例#6
0
 public static Bitmap Create(string contents, QREncodeMode mode, QRErrorLevel errorLevel) => CreateBitmap(contents, mode: mode, errorLevel: errorLevel);
示例#7
0
 public static Bitmap Create(string contents, QRErrorLevel errorLevel) => CreateBitmap(contents, errorLevel: errorLevel);
示例#8
0
        private static BarCodeBuilder CreateQrBuilder(string contents, QREncodeMode mode, QRErrorLevel errorLevel)
        {
            if (mode == QREncodeMode.Binary)
            {
                var bytes = Encoding.UTF8.GetBytes(contents);
                contents = ISO_8859_1.GetString(bytes);
            }

            BarCodeBuilder builder = new BarCodeBuilder(contents, Symbology.QR)
            {
                QRErrorLevel = errorLevel,
                QREncodeMode = mode,
                EnableEscape = true,
                CaptionAbove = new Caption {
                    Visible = false
                },
                CaptionBelow = new Caption {
                    Visible = false
                }
            };

            return(builder);
        }
示例#9
0
        private static Bitmap CreateBitmapImage(string contents, int?resolution, QREncodeMode mode, QRErrorLevel errorLevel)
        {
            var builder = CreateQrBuilder(contents, mode, errorLevel);

            if (resolution.HasValue)
            {
                return(builder.GetCustomSizeBarCodeImage(new Size(resolution.Value, resolution.Value), false));
            }

            return(builder.GetOnlyBarCodeImage());
        }