Exemple #1
0
        internal void DrawImage(ref System.DrawingCore.Bitmap bm, string qrcode)
        {
            Graphics g = null;

            g = Graphics.FromImage(bm);
            float mag = PixelConversions.GetMagnification(g, bm.Width, bm.Height, OptimalHeight, OptimalWidth);

            int barHeight = PixelConversions.PixelXFromMm(g, OptimalHeight * mag);
            int barWidth  = PixelConversions.PixelYFromMm(g, OptimalWidth * mag);
            var writer    = new ZXing.BarcodeWriterPixelData
            {
                Format  = ZXing.BarcodeFormat.CODE_39,
                Options = new QrCodeEncodingOptions
                {
                    Height = barHeight,
                    Width  = barWidth,
                    Margin = 0
                }
            };

            writer.Format         = ZXing.BarcodeFormat.QR_CODE;
            writer.Options.Height = barHeight;
            writer.Options.Width  = barWidth;

            bm = ConvertPixelDataToBitmap(writer.Write(qrcode));
        }
Exemple #2
0
        public void DrawImage(ref Bitmap bm, string code)
        {
#if NETSTANDARD2_0
            var writer = new ZXing.BarcodeWriter <Bitmap>();
#else
            var writer = new ZXing.BarcodeWriter();
#endif

            if (code.Length == 13)
            {
                writer.Format = ZXing.BarcodeFormat.EAN_13;
            }
            else if (code.Length == 8)
            {
                writer.Format = ZXing.BarcodeFormat.EAN_8;
            }
            else
            {
                writer.Format = ZXing.BarcodeFormat.CODE_128;
            }

            Graphics g = null;
            g = Graphics.FromImage(bm);
            float mag = PixelConversions.GetMagnification(g, bm.Width, bm.Height,
                                                          OptimalHeight, OptimalWidth);

            int barHeight = PixelConversions.PixelXFromMm(g, OptimalHeight * mag);
            int barWidth  = PixelConversions.PixelYFromMm(g, OptimalWidth * mag);

            writer.Options.Height      = barHeight;
            writer.Options.Width       = barWidth;
            writer.Options.PureBarcode = true;
            bm = writer.Write(code);
        }
Exemple #3
0
        internal void DrawImage(ref MemoryStream ms, string qrcode, int height, int weight)
        {
            Bitmap   bm = new Bitmap(weight, height);
            Graphics g  = null;

            g = Graphics.FromImage(bm);
            float mag = PixelConversions.GetMagnification(g, bm.Width, bm.Height, OptimalHeight, OptimalWidth);

            int barHeight = PixelConversions.PixelXFromMm(g, OptimalHeight * mag);
            int barWidth  = PixelConversions.PixelYFromMm(g, OptimalWidth * mag);
            var writer    = new ZXing.BarcodeWriterPixelData
            {
                Format  = ZXing.BarcodeFormat.CODE_39,
                Options = new QrCodeEncodingOptions
                {
                    Height = barHeight,
                    Width  = barWidth,
                    Margin = 0
                }
            };

            writer.Format         = ZXing.BarcodeFormat.QR_CODE;
            writer.Options.Height = barHeight;
            writer.Options.Width  = barWidth;

            //bm = ConvertPixelDataToBitmap(writer.Write(qrcode));
            ms = ConvertPixelDataToMemoryStream(writer.Write(qrcode));
        }
Exemple #4
0
        /// <summary>
        /// Does the actual drawing of the image.
        /// </summary>
        /// <param name="bm"></param>
        /// <param name="AztecCode"></param>
        internal void DrawImage(ref System.Drawing.Bitmap bm, string aztecCode)
        {
            var writer = new ZXing.BarcodeWriter();

            writer.Format = ZXing.BarcodeFormat.AZTEC;

            Graphics g = null;

            g = Graphics.FromImage(bm);
            float mag = PixelConversions.GetMagnification(g, bm.Width, bm.Height, OptimalHeight, OptimalWidth);

            int barHeight = PixelConversions.PixelXFromMm(g, OptimalHeight * mag);
            int barWidth  = PixelConversions.PixelYFromMm(g, OptimalWidth * mag);

            writer.Options.Height = barHeight;
            writer.Options.Width  = barWidth;


            bm = writer.Write(aztecCode);
        }
        public void DrawImage(ref Bitmap bm, string code)
        {
            com.google.zxing.oned.EAN8Writer   writer = new com.google.zxing.oned.EAN8Writer();
            com.google.zxing.common.ByteMatrix matrix;

            Graphics g = null;

            g = Graphics.FromImage(bm);
            float mag = PixelConversions.GetMagnification(g, bm.Width, bm.Height,
                                                          OptimalHeight, OptimalWidth);

            int barHeight = PixelConversions.PixelXFromMm(g, OptimalHeight * mag);
            int barWidth  = PixelConversions.PixelYFromMm(g, OptimalWidth * mag);

            matrix = writer.encode(code, com.google.zxing.BarcodeFormat.EAN_8,
                                   barWidth, barHeight, null);


            bm = new Bitmap(barWidth, barHeight);
            Color Color = Color.FromArgb(0, 0, 0);

            for (int y = 0; y < matrix.Height; ++y)
            {
                for (int x = 0; x < matrix.Width; ++x)
                {
                    Color pixelColor = bm.GetPixel(x, y);

                    //Find the colour of the dot
                    if (matrix.get_Renamed(x, y) == -1)
                    {
                        bm.SetPixel(x, y, Color.White);
                    }
                    else
                    {
                        bm.SetPixel(x, y, Color.Black);
                    }
                }
            }
        }
        public void DrawImage(ref Bitmap bm, string code128)
        {
            var writer = new ZXing.BarcodeWriter();

            writer.Format = ZXing.BarcodeFormat.CODE_128;

            Graphics g = null;

            g = Graphics.FromImage(bm);
            float mag = PixelConversions.GetMagnification(g, bm.Width, bm.Height,
                                                          OptimalHeight, OptimalWidth);

            int barHeight = PixelConversions.PixelXFromMm(g, OptimalHeight * mag);
            int barWidth  = PixelConversions.PixelYFromMm(g, OptimalWidth * mag);


            writer.Options.Height = barHeight;
            writer.Options.Width  = barWidth;


            bm = writer.Write(code128);
        }
Exemple #7
0
        /// <summary>
        /// Does the actual drawing of the image.
        /// </summary>
        /// <param name="bm"></param>
        /// <param name="qrcode"></param>
        internal void DrawImage(ref System.Drawing.Bitmap bm, string qrcode)
        {
#if NETSTANDARD2_0
            var writer = new ZXing.BarcodeWriter <Bitmap>();
#else
            var writer = new ZXing.BarcodeWriter();
#endif
            writer.Format = ZXing.BarcodeFormat.QR_CODE;

            Graphics g = null;
            g = Graphics.FromImage(bm);
            float mag = PixelConversions.GetMagnification(g, bm.Width, bm.Height, OptimalHeight, OptimalWidth);

            int barHeight = PixelConversions.PixelXFromMm(g, OptimalHeight * mag);
            int barWidth  = PixelConversions.PixelYFromMm(g, OptimalWidth * mag);

            writer.Options.Height = barHeight;
            writer.Options.Width  = barWidth;


            bm = writer.Write(qrcode);
        }
Exemple #8
0
        /// <summary>
        /// DrawImage given a Bitmap and a upcode does all the drawing work.
        /// </summary>
        /// <param name="bm"></param>
        /// <param name="upcode"></param>
        internal void DrawImage(System.DrawingCore.Bitmap bm, string upcode)
        {
            string   barPattern = this.GetEncoding(upcode);
            Graphics g          = null;

            g = Graphics.FromImage(bm);
            float mag = PixelConversions.GetMagnification(g, bm.Width, bm.Height, OptimalHeight, OptimalWidth);

            float barWidth     = ModuleWidth * mag;
            float barHeight    = OptimalHeight * mag;
            float fontHeight   = FontHeight * mag;
            float fontHeightMM = fontHeight / 72.27f * 25.4f;
            Font  f            = null;

            try
            {
                g.PageUnit = System.DrawingCore.GraphicsUnit.Millimeter;

                // Fill in the background with white
                g.FillRectangle(Brushes.White, 0, 0, bm.Width, bm.Height);

                // Draw the bars
                int barCount = LeftQuietZoneModules;
                foreach (char bar in barPattern)
                {
                    if (bar == '1')
                    {
                        float bh = ((barCount > ModulesToManufacturingStart && barCount < ModulesToManufacturingEnd) ||
                                    (barCount > ModulesToProductStart && barCount < ModulesToProductEnd)) ?
                                   barHeight - fontHeightMM : barHeight;

                        g.FillRectangle(Brushes.Black, barWidth * barCount, 0, barWidth, bh);
                    }
                    barCount++;
                }

                // Draw the human readable portion of the barcode
                f = new Font("Arial", fontHeight);

                // Draw the left guard text (i.e. 2nd digit of the NumberSystem)
                string wc = upcode.Substring(0, 1);
                g.DrawString(wc, f, Brushes.Black,
                             new PointF(barWidth * LeftQuietZoneModules - g.MeasureString(wc, f).Width, barHeight - fontHeightMM));

                // Draw the manufacturing digits
                wc = upcode.Substring(1, 6);
                g.DrawString(wc, f, Brushes.Black,
                             new PointF(barWidth * ModulesToManufacturingEnd - g.MeasureString(wc, f).Width, barHeight - fontHeightMM));

                // Draw the product code + the checksum digit
                wc = upcode.Substring(7, 5) + CheckSum(upcode).ToString();
                g.DrawString(wc, f, Brushes.Black,
                             new PointF(barWidth * ModulesToProductEnd - g.MeasureString(wc, f).Width, barHeight - fontHeightMM));
            }
            finally
            {
                if (f != null)
                {
                    f.Dispose();
                }
                if (g != null)
                {
                    g.Dispose();
                }
            }
        }