Exemple #1
0
        public void Print()
        {
            BarcodeDraw barcode = BarcodeDrawFactory.GetSymbology(BarcodeSymbology.Code93);
            Image       img     = barcode.Draw("1578", 25);

            img.Save("barcode93.png");
        }
Exemple #2
0
        public void PrintBarCode(string barcode, int start, int end)
        {
            var         bcType      = start.ToString(CultureInfo.InvariantCulture) + end.ToString(CultureInfo.InvariantCulture);
            BarcodeDraw barcodeDraw = BarcodeDrawFactory.Code128WithChecksum;

            if (bcType == "39")
            {
                barcodeDraw = BarcodeDrawFactory.Code39WithoutChecksum;
            }
            if (bcType == "13")
            {
                barcodeDraw = BarcodeDrawFactory.CodeEan13WithChecksum;
            }
            if (bcType == "25")
            {
                barcodeDraw = BarcodeDrawFactory.Code25StandardWithoutChecksum;
            }
            if (bcType == "08")
            {
                barcodeDraw = BarcodeDrawFactory.CodeEan8WithChecksum;
            }
            if (bcType == "11")
            {
                barcodeDraw = BarcodeDrawFactory.Code11WithoutChecksum;
            }
            if (bcType == "93")
            {
                barcodeDraw = BarcodeDrawFactory.Code93WithChecksum;
            }

            using (var img = barcodeDraw.Draw(barcode, 80, 1))
            {
                PrintBitmap(new Bitmap(img));
            }
        }
Exemple #3
0
        /// <summary>
        /// Draws the design-time representation of the barcode.
        /// </summary>
        /// <param name="g">The g.</param>
        /// <param name="dp">The dp.</param>
        public override void Draw(Graphics g, ReportItemDrawParams dp)
        {
            // Our background is always white
            if (dp.DrawBackground)
            {
                g.Clear(Color.White);
            }

            // Delegate drawing of outlines
            if (dp.DrawOutlines)
            {
                base.Draw(g, dp.AsOutlinesOnly());
            }

            // Draw content if we can...
            if (dp.DrawContent &&
                Symbology != BarcodeSymbology.Unknown &&
                !string.IsNullOrEmpty(Text))
            {
                BarcodeDraw drawObject =
                    BarcodeDrawFactory.GetSymbology(Symbology);
                using (System.Drawing.Image image = drawObject.Draw(
                           Text,
                           InterGlyphSpacing,
                           MinimumBarHeight,
                           MaximumBarHeight,
                           MinimumBarWidth,
                           MaximumBarWidth))
                {
                    g.DrawImage(image, new Point(0, 0));
                }
            }
        }
Exemple #4
0
        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            Graphics g = e.Graphics;

            CodeQrBarcodeDraw QRcode = BarcodeDrawFactory.CodeQr; // to generate QR code

            System.Drawing.Image QRcodeImage = QRcode.Draw(coilID.Text, 100);
            // RectangleF(The coordinates of the upper-left corner of the rectangle, width, height)
            RectangleF QRcodeRect = new RectangleF(50.0F, 40.0F, 150.0F, 150.0F);

            g.DrawImage(QRcodeImage, QRcodeRect);

            BarcodeDraw bdraw = BarcodeDrawFactory.GetSymbology(BarcodeSymbology.Code128);

            System.Drawing.Image barcodeImage = bdraw.Draw(coilID.Text, 100);
            RectangleF           barcodeRect  = new RectangleF(250.0F, 40.0F, 400.0F, 100.0F);

            g.DrawImage(barcodeImage, barcodeRect);

            // Create string to draw.
            String drawString = coilID.Text;

            // Create font and brush.
            System.Drawing.Font drawFont  = new System.Drawing.Font("Times New Roman", 16);
            SolidBrush          drawBrush = new SolidBrush(Color.Black);

            // Create point for upper-left corner of drawing.
            float x = 250.0F;
            float y = 150.0F;

            g.DrawString(drawString, drawFont, drawBrush, x, y);
        }
Exemple #5
0
        // On each printed page...
        protected override void OnPrintPage(PrintPageEventArgs e)
        {
            Graphics graphics = e.Graphics;

            // For the barcode printing
            BarcodeDraw bdraw        = BarcodeDrawFactory.GetSymbology(BarcodeSymbology.Code128);
            Image       barcodeImage = bdraw.Draw(ContainerCode, 40);

            Pen _pen = new Pen(Brushes.Black);

            _pen.DashPattern = new float[] { 4.0F, 2.0F, 1.0F, 3.0F };

            Pager.Active = false;
            AddArea(EnumDocumentZones.BODY);

            // Set font
            //this.CurrentFont = new Font("Courier New", 15, FontStyle.Bold);
            for (var i = 0; i < 2; i++)
            {
                AddText("DEALER PICK PACK CONTAINER", new EspackFont("Courier New", 11, FontStyle.Bold | FontStyle.Underline), pEOL: true);
                AddText($"{ContainerCode,-10}", new EspackFont("Courier New", 26, FontStyle.Bold), pEOL: true);
                AddImage(barcodeImage, pWidth: 600, pEOL: true);
                AddText($"ROUTE: {Route,-8}", new EspackFont("Courier New", 12, FontStyle.Bold), pEOL: true);
                AddText($"DATE : {Date,-10}", new EspackFont("Courier New", 12, FontStyle.Bold), pEOL: true);
                AddText("", pEOL: true);
            }

            AddDrawing(0, 140, 400, 140, EnumDrawingType.LINE, _pen);
            // Base code
            base.OnPrintPage(e);
        }
Exemple #6
0
        private byte[] DrawImage()
        {
            // Determine barcode symbology
            BarcodeSymbology symbology     = BarcodeSymbology.Unknown;
            string           symbologyText = (string)GetCustomProperty("barcode:Symbology");

            symbology = (BarcodeSymbology)Enum.Parse(typeof(BarcodeSymbology), symbologyText);
            if (symbology != BarcodeSymbology.Unknown)
            {
                // Create draw object
                BarcodeDraw drawObject = BarcodeDrawFactory.GetSymbology(symbology);

                // Get default metrics and override with values specified in CRI
                BarcodeMetrics metrics = drawObject.GetDefaultMetrics(
                    GetCustomPropertyInt32("barcode:MaximumBarHeight", 30));
                metrics.MinHeight =
                    GetCustomPropertyInt32("barcode:MinimumBarHeight", metrics.MinHeight);
                metrics.MinWidth =
                    GetCustomPropertyInt32("barcode:MinimumBarWidth", metrics.MinWidth);
                metrics.MaxWidth =
                    GetCustomPropertyInt32("barcode:MaximumBarWidth", metrics.MaxWidth);
                metrics.InterGlyphSpacing =
                    GetCustomPropertyInt32("barcode:InterGlyphSpacing", metrics.InterGlyphSpacing);

                // Get the text to render
                string textToRender = (string)GetCustomProperty("barcode:Text");

                // Determine available space for rendering
                int criWidth  = (int)(_cri.Width.ToInches() * DPI);
                int criHeight = (int)(_cri.Height.ToInches() * DPI);

                // Create bitmap of the appropriate size
                System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(
                    criWidth, criHeight, PixelFormat.Format32bppArgb);
                using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp))
                {
                    // Clear entire background
                    g.Clear(System.Drawing.Color.White);

                    // Get barcode image
                    System.Drawing.Image barcodeImage =
                        drawObject.Draw(textToRender, metrics);

                    // Centre the image
                    int x = (bmp.Width - barcodeImage.Width) / 2;
                    int y = (bmp.Height - barcodeImage.Height) / 2;
                    g.DrawImageUnscaled(barcodeImage, x, y);
                }

                // Create memory stream for new image
                using (MemoryStream stream = new MemoryStream())
                {
                    // Save image and setup CRI image
                    bmp.Save(stream, ImageFormat.Bmp);
                    return(stream.ToArray());
                }
            }
            return(null);
        }
Exemple #7
0
        private void button2_Click(object sender, EventArgs e)
        {
            // + "\nPhone : " + phonetxt.Text + "\nAge :" + agetxt.Text + "\nGender :" + genderCb.Text
            BarcodeDraw drawbar = BarcodeDrawFactory.CodeQr;
            var         qrText  = "First Name :" + Firstnametxt.Text + "\nLast Name :" + lastnametxt.Text + "\nFather Name :" + fathernametxt.Text;

            pictureBox1.Image   = drawbar.Draw(qrText, 50);
            pictureBox1.Visible = true;
        }
        /// <summary>
        /// Draws the design-time representation of the barcode.
        /// </summary>
        /// <param name="g">
        /// A <see cref="Graphics"/> object representing the designer surface.
        /// </param>
        /// <param name="dp">
        /// A <see cref="ReportItemDrawParams"/> containing draw parameters.
        /// </param>
        public override void Draw(Graphics g, ReportItemDrawParams dp)
        {
            // Our background is always white
            if (dp.DrawBackground)
            {
                g.Clear(Color.White);
            }

            // Delegate drawing of outlines
            if (dp.DrawOutlines)
            {
                base.Draw(g, dp.AsOutlinesOnly());
            }

            // Draw content if we can...
            if (dp.DrawContent &&
                Symbology != BarcodeSymbology.Unknown &&
                !string.IsNullOrEmpty(Text))
            {
                BarcodeDraw drawObject =
                    BarcodeDrawFactory.GetSymbology(Symbology);

                BarcodeMetrics metrics = drawObject.GetDefaultMetrics(30);
                metrics.Scale = Scale;

                BarcodeMetrics1d metrics1d = metrics as BarcodeMetrics1d;
                if (metrics1d != null)
                {
                    metrics1d.InterGlyphSpacing = InterGlyphSpacing;
                    metrics1d.MaxHeight         = MaximumBarHeight;
                    metrics1d.MinHeight         = MinimumBarHeight;
                    metrics1d.MaxWidth          = MaximumBarWidth;
                    metrics1d.MinWidth          = MinimumBarWidth;
                    metrics1d.RenderVertically  = RenderVertically;
                }
                else if (Symbology == BarcodeSymbology.CodeQr)
                {
                    BarcodeMetricsQr qrMetrics = (BarcodeMetricsQr)metrics;
                    if (QrVersion != null)
                    {
                        qrMetrics.Version = QrVersion.Value;
                    }
                    if (QrEncodingMode != null)
                    {
                        qrMetrics.EncodeMode = QrEncodingMode.Value;
                    }
                    if (QrErrorCorrectionMode != null)
                    {
                        qrMetrics.ErrorCorrection = QrErrorCorrectionMode.Value;
                    }
                }
                using (System.Drawing.Image image = drawObject.Draw(Text, metrics))
                {
                    g.DrawImage(image, new Point(0, 0));
                }
            }
        }
        protected override void OnRender(DrawingContext drawingContext)
        {
            var size = new Rect(0, 0, ActualWidth, ActualHeight);

            drawingContext.DrawRectangle(Brushes.White, null, size);
            if (!string.IsNullOrEmpty(Barcode))
            {
                BarcodeDraw.Draw(drawingContext, Barcode, new BarcodeMetrics1d(1, 2, 50), size);
            }
        }
Exemple #10
0
        public static void PrintStickerFromMnf(string path)
        {
            FSharpOption <Tuple <FSharpOption <Bitmap>, string, FSharpList <Tuple <string, string> > > > fSharpOption  = EtiketParse(path);
            FSharpOption <Tuple <FSharpOption <Bitmap>, string, FSharpList <Tuple <string, string> > > > fSharpOption2 = fSharpOption;
            FSharpOption <Tuple <FSharpOption <Bitmap>, string, FSharpList <Tuple <string, string> > > > fSharpOption3 = fSharpOption2;

            if (fSharpOption3 != null)
            {
                FSharpOption <Tuple <FSharpOption <Bitmap>, string, FSharpList <Tuple <string, string> > > > fSharpOption4 = fSharpOption3;
                if (fSharpOption4.Value.Item1 != null)
                {
                    FSharpOption <Bitmap> item = fSharpOption4.Value.Item1;
                    FSharpList <Tuple <string, string> > lst2 = fSharpOption4.Value.Item3;
                    Bitmap bmp   = item.Value;
                    string barc2 = fSharpOption4.Value.Item2;
                    using (MemoryStream stream = new MemoryStream(File.ReadAllBytes(Path.Combine(libPath, "stickerImp.xaml"))))
                    {
                        object obg  = XamlReader.Load((Stream)stream);
                        Window win2 = (Window)obg;
                        //Window win2 = (Window)XamlReader.Load((Stream)stream);
                        Grid sticker2 = (Grid)win2.FindName("sticker");
                        System.Windows.Controls.Image barcod2 = (System.Windows.Controls.Image)win2.FindName("barcod");
                        System.Windows.Controls.Image imgWin  = (System.Windows.Controls.Image)win2.FindName("imgWin");
                        imgWin.Source = /*Bitmap.*/ get_Source(bmp);
                        ListModule.Iterate(new PrintStickerFromMnf_132_1(win2), lst2);
                        BarcodeDraw brc2 = BarcodeDrawFactory.GetSymbology(BarcodeSymbology.Code128);
                        barcod2.Source = /*Bitmap.*/ get_Source((Bitmap)brc2.Draw(barc2, 30));
                        PrintGrid(sticker2);
                        Unit unit = null;
                    }
                }
                else
                {
                    FSharpList <Tuple <string, string> > lst = fSharpOption4.Value.Item3;
                    string barc = fSharpOption4.Value.Item2;
                    using (MemoryStream ms = new MemoryStream(File.ReadAllBytes(Path.Combine(libPath, "stickerBlk.xaml"))))
                    {
                        object obg = XamlReader.Load((Stream)ms);
                        Window win = (Window)obg;
                        //Window win = (Window)XamlReader.Load((Stream)ms);
                        Grid sticker = (Grid)win.FindName("sticker");
                        System.Windows.Controls.Image barcod = (System.Windows.Controls.Image)win.FindName("barcod");
                        ListModule.Iterate(new PrintStickerFromMnf_121(win), lst);
                        BarcodeDraw brc = BarcodeDrawFactory.GetSymbology(BarcodeSymbology.Code128);
                        barcod.Source = /*Bitmap.*/ get_Source((Bitmap)brc.Draw(barc, 30));
                        PrintGrid(sticker);
                        Unit unit2 = null;
                    }
                }
            }
        }
Exemple #11
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Zen.Barcode.Code128BarcodeDraw barcode = Zen.Barcode.BarcodeDrawFactory.Code128WithChecksum;
            //pictureBox1.Image = barcode.Draw(textBox1.Text, 50);

            if (textBox1.Text != "")
            {
                BarcodeSymbology s          = BarcodeSymbology.Code128;
                BarcodeDraw      drawObject = BarcodeDrawFactory.GetSymbology(s);
                var metrics = drawObject.GetDefaultMetrics(60);
                metrics.Scale     = 2;
                pictureBox1.Image = drawObject.Draw(textBox1.Text, metrics);
            }
        }
Exemple #12
0
        private static string getBarcode(string barcode)
        {
            BarcodeSymbology s          = BarcodeSymbology.Code39NC;
            BarcodeDraw      drawObject = BarcodeDrawFactory.GetSymbology(s);
            var metrics = drawObject.GetDefaultMetrics(45);

            metrics.Scale = 1;
            var barcodeImage = drawObject.Draw(barcode, metrics);

            using (MemoryStream ms = new MemoryStream())
            {
                barcodeImage.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                byte[] imageBytes = ms.ToArray();

                return(Convert.ToBase64String(imageBytes));
            }
        }
Exemple #13
0
        public static byte[] GenerarImagenCodigoBarras(string codigo, int idTipoCodigoBarras, decimal altoMaximo)
        {
            if (idTipoCodigoBarras <= 0 || string.IsNullOrWhiteSpace(codigo))
            {
                return(null);
            }


            BarcodeDraw barcodeDraw = BarcodeDrawFactory.Code128WithChecksum;

            switch (idTipoCodigoBarras)
            {
            case 1:
                barcodeDraw = BarcodeDrawFactory.Code11WithChecksum;
                break;

            case 2:
                barcodeDraw = BarcodeDrawFactory.Code25StandardWithChecksum;
                break;

            case 3:
                barcodeDraw = BarcodeDrawFactory.Code39WithChecksum;
                break;

            case 4:
                barcodeDraw = BarcodeDrawFactory.Code93WithChecksum;
                break;

            case 5:
                barcodeDraw = BarcodeDrawFactory.Code128WithChecksum;
                break;

            case 6:
                barcodeDraw = BarcodeDrawFactory.CodePdf417;
                break;
            }

            var bitmap = new Bitmap(barcodeDraw.Draw(codigo, (int)altoMaximo));

            var memoryStream = new MemoryStream();

            bitmap.Save(memoryStream, ImageFormat.Png);
            var bitmapBytes = memoryStream.ToArray();

            return(bitmapBytes);
        }
Exemple #14
0
            private void StartAsyncTask(object state)
            {
                try
                {
                    // We want to respond to image requests of the form;
                    //
                    //	<encoded barcode>.Barcode

                    // Cache information from context
                    _request  = _context.Request;
                    _response = _context.Response;

                    // Filename is the encoded design ID
                    BarcodeImageUri uri = new BarcodeImageUri(_request.Url);

                    // Lookup design and retrieve image data
                    // Stream JPEG image to client
                    _response.ContentType = "image/jpeg";
                    _response.Clear();
                    _response.BufferOutput = true;

                    // Get the object capable of rendering the barcode
                    BarcodeDraw drawObject = BarcodeDrawFactory.GetSymbology(
                        uri.EncodingScheme);

                    // Render barcode and save directly onto response stream
                    using (Image image = drawObject.Draw(uri.Text,
                                                         uri.BarMinHeight, uri.BarMaxHeight,
                                                         uri.BarMinWidth, uri.BarMaxWidth))
                    {
                        image.Save(_response.OutputStream, ImageFormat.Jpeg);
                    }
                }
                catch (Exception e)
                {
                    _error = e;
                }
                finally
                {
                    _response.End();
                    SetComplete();
                }
            }
        public string getBarcode(int type, long n)
        {
            Zen.Barcode.BarcodeSymbology s = Zen.Barcode.BarcodeSymbology.Code39C;
            BarcodeDraw drawObject         = BarcodeDrawFactory.GetSymbology(s);

            var metrics = drawObject.GetDefaultMetrics(100);

            metrics.Scale = 1;
            var barcodeImage = drawObject.Draw(n.ToString(), metrics);

            Bitmap bm = ResizeImage(barcodeImage, 398, 60);

            using (MemoryStream ms = new MemoryStream())
            {
                //barcodeImage.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                bm.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                //bm.Save(@"C:\test\BarCode(3).jpeg", System.Drawing.Imaging.ImageFormat.Jpeg);
                byte[] imageBytes = ms.ToArray();
                return(string.Format("data:image/png;base64,{0}", Convert.ToBase64String(imageBytes)));
            }
        }
Exemple #16
0
        /// <summary>
        /// Gets the barcode image based on the current barcode builder
        /// properties.
        /// </summary>
        /// <returns>
        /// Returns a raw byte array of the barcode in standard BMP format.
        /// </returns>
        public byte[] GetBarcodeImage()
        {
            // Sanity check
            if (Symbology == BarcodeSymbology.Unknown)
            {
                return(null);
            }

            // Draw image
            BarcodeDraw drawObject = BarcodeDrawFactory.GetSymbology(Symbology);

            using (Image image = drawObject.Draw(Text, _metrics))
            {
                // Create memory stream for new image
                using (MemoryStream stream = new MemoryStream())
                {
                    // Save image and return raw byte array
                    image.Save(stream, ImageFormat.Bmp);
                    return(stream.ToArray());
                }
            }
        }
Exemple #17
0
        public static System.IO.MemoryStream GetQRCodeImage(string serialNo)
        {
            //Code128BarcodeDraw bdf = BarcodeDrawFactory.Code128WithChecksum;
            //System.Drawing.Image img = bdf.Draw(serialNo, 55, 2);

            BarcodeSymbology s          = BarcodeSymbology.Code128;
            BarcodeDraw      drawObject = BarcodeDrawFactory.CodeQr;
            var metrics = drawObject.GetDefaultMetrics(50);

            metrics.Scale = 5;
            var img = drawObject.Draw(serialNo, metrics);

            ImageConverter ic = new ImageConverter();

            Byte[] ba = (Byte[])ic.ConvertTo(img, typeof(Byte[]));

            MemoryStream memoryStream = new MemoryStream(ba);

            memoryStream.Flush();
            memoryStream.Seek(0, SeekOrigin.Begin);

            return(memoryStream);
        }
Exemple #18
0
        public byte[] CreateBarcode()
        {
            if (!String.IsNullOrEmpty(Code))
            {
                MemoryStream ms = new MemoryStream();

                BarcodeDraw d = BarcodeDrawFactory.Code128WithChecksum;

                var metrics = d.GetDefaultMetrics(60);

                metrics.Scale = 2;

                var i = d.Draw(Code, metrics);

                i.Save(ms, ImageFormat.Jpeg);

                return(ms.ToArray());
            }
            else
            {
                return(new byte[0]);
            }
        }
        /// <summary>
        /// Enables processing of HTTP Web requests by a custom HttpHandler
        /// that implements the <see cref="T:System.Web.IHttpHandler"/> interface.
        /// </summary>
        /// <param name="context">
        /// An <see cref="T:System.Web.HttpContext"/> object that provides
        /// references to the intrinsic server objects (for example, Request,
        /// Response, Session, and Server) used to service HTTP requests.
        /// </param>
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                // We want aggressive caching since the barcode will not change
                //	for a given set of request parameters however we disable
                //	caching on proxy servers...
                context.Response.Cache.SetCacheability(HttpCacheability.ServerAndPrivate);

                // Determine the symbology desired
                string           symbologyText = context.Request.QueryString["sym"];
                BarcodeSymbology symbology;
                if (!TryParseEnum <BarcodeSymbology>(symbologyText, true, out symbology) ||
                    symbology == BarcodeSymbology.Unknown)
                {
                    throw new ArgumentException("Unable to determine symbology.");
                }

                // Get the text to render from the context
                // NOTE: We URL decode it first...
                string textToRender =
                    context.Server.UrlDecode(
                        context.Request.QueryString["text"]);
                if (string.IsNullOrEmpty(textToRender))
                {
                    throw new ArgumentException("Must have text to render as barcode.");
                }

                // Get the rendering metrics from the context
                BarcodeMetrics metrics = GetBarcodeMetricsFromContext(context, symbology);

                // Determine the image format (default is jpeg)
                RenderImageFormat format;
                string            imageFormatText = context.Request.QueryString["itype"];
                if (!TryParseEnum <RenderImageFormat>(imageFormatText, true, out format))
                {
                    format = RenderImageFormat.Jpeg;
                }

                // Setup content-type and image format for saving
                ImageFormat imageFormat;
                switch (format)
                {
                case RenderImageFormat.Jpeg:
                    imageFormat = ImageFormat.Jpeg;
                    context.Response.ContentType = "image/jpeg";
                    break;

                case RenderImageFormat.Png:
                    imageFormat = ImageFormat.Png;
                    context.Response.ContentType = "image/png";
                    break;

                default:
                    throw new ArgumentException(
                              "Unexpected rendering image format encountered.");
                }

                // If we can find an encoder for the image type then attempt
                //	to set top quality and monochrome colour depth.
                ImageCodecInfo codecInfo = ImageCodecInfo.GetImageEncoders()
                                           .FirstOrDefault((item) => item.FormatID == imageFormat.Guid);
                EncoderParameters codecParameters = null;
                if (codecInfo != null)
                {
                    // Two parameters; maximum quality and monochrome
                    codecParameters          = new EncoderParameters(2);
                    codecParameters.Param[0] = new EncoderParameter(Encoder.Quality, 100L);
                    codecParameters.Param[1] = new EncoderParameter(Encoder.ColorDepth, 2);
                }

                // Create instance of barcode rendering engine
                BarcodeDraw drawObject = BarcodeDrawFactory.GetSymbology(symbology);
                using (Image image = drawObject.Draw(textToRender, metrics))
                {
                    // Save image to the response stream directly
                    // TODO: Should the response have buffer enabled?
                    if (codecInfo == null)
                    {
                        image.Save(context.Response.OutputStream, imageFormat);
                    }
                    else
                    {
                        image.Save(context.Response.OutputStream, codecInfo, codecParameters);
                    }
                }

                // Set status and finalise request handling.
                context.Response.StatusCode = 200;
                context.Response.End();
            }
            catch (Exception)
            {
                // TODO: Log the error and return a 500...
                context.Response.StatusCode = 500;
                context.Response.End();
            }
        }
Exemple #20
0
        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            Graphics g = e.Graphics;

            if (BackColorText.Text == "")
            {
                label = RackNumberText.Text + "+" + TypeText.Text + "+" + FrontColorText.Text + "+" + comboBox1.Text;
            }
            else
            {
                label = RackNumberText.Text + "+" + TypeText.Text + "+" + FrontColorText.Text.Substring(0, 2) + BackColorText.Text.Substring(0, 2) + "+" + comboBox1.Text;
            }

            CodeQrBarcodeDraw QRcode = BarcodeDrawFactory.CodeQr; // to generate QR code

            System.Drawing.Image QRcodeImage = QRcode.Draw(label, 100);
            // RectangleF(The coordinates of the upper-left corner of the rectangle, width, height)
            RectangleF QRcodeRect = new RectangleF(20.0F, 40.0F, 150.0F, 150.0F);

            g.DrawImage(QRcodeImage, QRcodeRect);

            BarcodeDraw bdraw = BarcodeDrawFactory.GetSymbology(BarcodeSymbology.Code128);

            System.Drawing.Image barcodeImage = bdraw.Draw(label, 100);
            RectangleF           barcodeRect  = new RectangleF(350.0F, 60.0F, 430.0F, 110.0F);

            g.DrawImage(barcodeImage, barcodeRect);

            // Create string to draw.
            String drawString = label.ToUpper();

            // center the text in a specified rectangle.
            StringFormat sf = new StringFormat();

            sf.LineAlignment = StringAlignment.Center;
            sf.Alignment     = StringAlignment.Center;

            SolidBrush drawBrush;

            // Back color
            if (BackColorText.Text != "")
            {
                drawBrush = new SolidBrush(Color.White);
                System.Drawing.Font colorFont2 = new System.Drawing.Font("Ariel", 40, FontStyle.Bold);
                g.FillRectangle(new SolidBrush(Color.Black), 170, 125, 170, 60);

                RectangleF colorRect2 = new RectangleF(160.0F, 120.0F, 180.0F, 80.0F);
                g.DrawString(BackColorText.Text.ToUpper(), colorFont2, drawBrush, colorRect2, sf);
            }

            // front color
            drawBrush = new SolidBrush(Color.Black);

            System.Drawing.Font colorFont = new System.Drawing.Font("Arial Black", 50, FontStyle.Bold);
            RectangleF          colorRect = new RectangleF(150.0F, 40.0F, 220.0F, 80.0F);

            g.DrawString(FrontColorText.Text.ToUpper(), colorFont, drawBrush, colorRect, sf);

            // type
            System.Drawing.Font typeFont = new System.Drawing.Font("Ariel", 30, FontStyle.Bold);
            RectangleF          typeRect = new RectangleF(400.0F, 15.0F, 100.0F, 60.0F);

            g.DrawString(TypeText.Text.ToUpper(), typeFont, drawBrush, typeRect, sf);

            // date
            string month_year = DateTime.Now.ToString("MMM").ToUpper() + "_" + DateTime.Now.ToString("yy");

            System.Drawing.Font timeFont = new System.Drawing.Font("Ariel", 20, FontStyle.Bold);
            RectangleF          timeRect = new RectangleF(550.0F, 15.0F, 150.0F, 60.0F);

            g.DrawString(month_year, timeFont, drawBrush, timeRect, sf);

            // width
            System.Drawing.Font widthFont = new System.Drawing.Font("Ariel", 30, FontStyle.Bold);
            RectangleF          widthRect = new RectangleF(700.0F, 15.0F, 100.0F, 60.0F);

            g.DrawString(comboBox1.Text, widthFont, drawBrush, widthRect, sf);

            // Coil ID
            System.Drawing.Font drawFont = new System.Drawing.Font("Ariel", 16);

            // Create point for upper-left corner of drawing.
            float x = 345.0F;
            float y = 170.0F;

            g.DrawString(drawString, drawFont, drawBrush, x, y);
            return;
        }
Exemple #21
0
        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            while (pageNumber < slitLabels.Length)
            {
                Graphics g = e.Graphics;

                CodeQrBarcodeDraw    QRcode      = BarcodeDrawFactory.CodeQr; // to generate QR code
                System.Drawing.Image QRcodeImage = QRcode.Draw(slitLabels[pageNumber], 100);
                // RectangleF(The coordinates of the upper-left corner of the rectangle, width, height)
                RectangleF QRcodeRect = new RectangleF(20.0F, 40.0F, 150.0F, 150.0F);
                g.DrawImage(QRcodeImage, QRcodeRect);

                BarcodeDraw          bdraw        = BarcodeDrawFactory.GetSymbology(BarcodeSymbology.Code128);
                System.Drawing.Image barcodeImage = bdraw.Draw(slitLabels[pageNumber], 100);
                RectangleF           barcodeRect  = new RectangleF(350.0F, 60.0F, 430.0F, 110.0F);
                g.DrawImage(barcodeImage, barcodeRect);

                // Create string to draw.
                String drawString = slitLabels[pageNumber].ToUpper();

                // center the text in a specified rectangle.
                StringFormat sf = new StringFormat();
                sf.LineAlignment = StringAlignment.Center;
                sf.Alignment     = StringAlignment.Center;

                SolidBrush drawBrush;

                // Back color
                if (TYPE.ToUpper() == "SM")
                {
                    COLOR     = SMFrontColorText.Text;
                    drawBrush = new SolidBrush(Color.White);
                    System.Drawing.Font colorFont2 = new System.Drawing.Font("Ariel", 40, FontStyle.Bold);
                    g.FillRectangle(new SolidBrush(Color.Black), 170, 125, 170, 60);

                    RectangleF colorRect2 = new RectangleF(160.0F, 120.0F, 180.0F, 80.0F);
                    g.DrawString(SMBackColorText.Text.ToUpper(), colorFont2, drawBrush, colorRect2, sf);
                }

                // front color
                drawBrush = new SolidBrush(Color.Black);

                System.Drawing.Font colorFont = new System.Drawing.Font("Arial Black", 50, FontStyle.Bold);
                RectangleF          colorRect = new RectangleF(150.0F, 40.0F, 220.0F, 80.0F);
                g.DrawString(COLOR.ToUpper(), colorFont, drawBrush, colorRect, sf);

                // type
                System.Drawing.Font typeFont = new System.Drawing.Font("Ariel", 30, FontStyle.Bold);
                RectangleF          typeRect = new RectangleF(400.0F, 15.0F, 100.0F, 60.0F);
                g.DrawString(TYPE.ToUpper(), typeFont, drawBrush, typeRect, sf);

                // date
                string month_year            = DateTime.Now.ToString("MMM").ToUpper() + "_" + DateTime.Now.ToString("yy");
                System.Drawing.Font timeFont = new System.Drawing.Font("Ariel", 20, FontStyle.Bold);
                RectangleF          timeRect = new RectangleF(550.0F, 15.0F, 150.0F, 60.0F);
                g.DrawString(month_year, timeFont, drawBrush, timeRect, sf);

                // width
                string width = slitLabels[pageNumber].Split('+')[5];
                System.Drawing.Font widthFont = new System.Drawing.Font("Ariel", 30, FontStyle.Bold);
                RectangleF          widthRect = new RectangleF(700.0F, 15.0F, 100.0F, 60.0F);
                g.DrawString(width, widthFont, drawBrush, widthRect, sf);

                // Coil ID
                System.Drawing.Font drawFont = new System.Drawing.Font("Ariel", 16);

                // Create point for upper-left corner of drawing.
                float x = 345.0F;
                float y = 170.0F;
                g.DrawString(drawString, drawFont, drawBrush, x, y);

                if (TYPE.ToUpper() == "SM")
                {
                    pageNumber++;
                }
                else
                {
                    pageNumber += 2;
                }

                if (pageNumber < slitLabels.Length)
                {
                    e.HasMorePages = true; //e.HasMorePages raised the PrintPage event once per page .
                }
                return;
            }
        }
        private byte[] DrawImage()
        {
            // Determine barcode symbology
            BarcodeSymbology symbology     = BarcodeSymbology.Unknown;
            string           symbologyText = (string)GetCustomProperty("barcode:Symbology");

            symbology = (BarcodeSymbology)Enum.Parse(typeof(BarcodeSymbology), symbologyText);
            if (symbology != BarcodeSymbology.Unknown)
            {
                // Create draw object
                BarcodeDraw drawObject = BarcodeDrawFactory.GetSymbology(symbology);

                // Get default metrics and override with values specified in CRI
                // TODO: Need more elegant method for doing this...
                BarcodeMetrics metrics = drawObject.GetDefaultMetrics(30);
                metrics.Scale =
                    GetCustomPropertyInt32("barcode:Scale", metrics.Scale);

                BarcodeMetrics1d metrics1d = metrics as BarcodeMetrics1d;
                if (metrics1d != null)
                {
                    metrics1d.MaxHeight =
                        GetCustomPropertyInt32("barcode:MaximumBarHeight", metrics1d.MaxHeight);
                    metrics1d.MinHeight =
                        GetCustomPropertyInt32("barcode:MinimumBarHeight", metrics1d.MinHeight);
                    metrics1d.MinWidth =
                        GetCustomPropertyInt32("barcode:MinimumBarWidth", metrics1d.MinWidth);
                    metrics1d.MaxWidth =
                        GetCustomPropertyInt32("barcode:MaximumBarWidth", metrics1d.MaxWidth);
                    int interGlyphSpacing =
                        GetCustomPropertyInt32("barcode:InterGlyphSpacing", -1);
                    if (interGlyphSpacing >= 0)
                    {
                        metrics1d.InterGlyphSpacing = interGlyphSpacing;
                    }
                    metrics1d.RenderVertically =
                        GetCustomPropertyBool("barcode:RenderVertically", metrics1d.RenderVertically);
                }
                else if (symbology == BarcodeSymbology.CodeQr)
                {
                    BarcodeMetricsQr qrMetrics = (BarcodeMetricsQr)metrics;
                    qrMetrics.Version =
                        GetCustomPropertyInt32("barcode:QrVersion", qrMetrics.Version);
                    qrMetrics.EncodeMode = (QrEncodeMode)
                                           GetCustomPropertyInt32("barcode:QrEncodeMode", (int)qrMetrics.EncodeMode);
                    qrMetrics.ErrorCorrection = (QrErrorCorrection)
                                                GetCustomPropertyInt32("barcode:QrErrorCorrection", (int)qrMetrics.ErrorCorrection);
                }

                // Get the text to render
                string textToRender = (string)GetCustomProperty("barcode:Text");

                // Determine available space for rendering
                int criWidth  = (int)(_cri.Width.ToInches() * DPI);
                int criHeight = (int)(_cri.Height.ToInches() * DPI);

                // Create bitmap of the appropriate size
                System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(
                    criWidth, criHeight, PixelFormat.Format32bppArgb);
                using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp))
                {
                    // Clear entire background
                    g.Clear(System.Drawing.Color.White);

                    // Get barcode image
                    System.Drawing.Image barcodeImage =
                        drawObject.Draw(textToRender, metrics);

                    // Centre the image
                    int x = (bmp.Width - barcodeImage.Width) / 2;
                    int y = (bmp.Height - barcodeImage.Height) / 2;
                    g.DrawImageUnscaled(barcodeImage, x, y);
                }

                // Create memory stream for new image
                using (MemoryStream stream = new MemoryStream())
                {
                    // Save image and setup CRI image
                    bmp.Save(stream, ImageFormat.Bmp);
                    return(stream.ToArray());
                }
            }
            return(null);
        }
Exemple #23
0
            private void StartAsyncTask(object state)
            {
                try
                {
                    // We want to respond to image requests of the form;
                    //
                    //	<encoded barcode>.Barcode

                    // Cache information from context
                    _request  = _context.Request;
                    _response = _context.Response;

                    // Filename is the encoded design ID
                    BarcodeImageUri uri = new BarcodeImageUri(_request.Url);

                    // Lookup design and retrieve image data
                    // Stream JPEG image to client
                    _response.ContentType = "image/jpeg";
                    _response.Clear();
                    _response.BufferOutput = true;

                    // Get the object capable of rendering the barcode
                    BarcodeDraw drawObject =
                        BarcodeDrawFactory.GetSymbology(uri.EncodingScheme);

                    BarcodeMetrics metrics = drawObject.GetDefaultMetrics(30);
                    metrics.Scale = uri.Scale;

                    BarcodeMetrics1d metrics1d = metrics as BarcodeMetrics1d;
                    if (metrics1d != null)
                    {
                        metrics1d.MaxHeight = uri.BarMaxHeight;
                        metrics1d.MinHeight = uri.BarMinHeight;
                        metrics1d.MaxWidth  = uri.BarMaxWidth;
                        metrics1d.MinWidth  = uri.BarMinWidth;
                    }
                    else if (uri.EncodingScheme == BarcodeSymbology.CodeQr)
                    {
                        BarcodeMetricsQr qrMetrics = (BarcodeMetricsQr)metrics;
                        qrMetrics.EncodeMode      = uri.QrEncodingMode;
                        qrMetrics.ErrorCorrection = uri.QrErrorCorrect;
                        qrMetrics.Version         = uri.QrVersion;
                    }

                    // Render barcode and save directly onto response stream
                    MemoryStream imageStream = new MemoryStream();
                    using (Image image = drawObject.Draw(uri.Text, metrics))
                    {
                        // Save to temporary stream because image tried to seek
                        //	during the write operation
                        image.Save(imageStream, ImageFormat.Jpeg);

                        // Move to start of the stream
                        imageStream.Seek(0, SeekOrigin.Begin);

                        // Do synchronous copy to response output stream
                        int    blockSize = 1024;
                        byte[] buffer    = new byte[blockSize];
                        while (true)
                        {
                            int bytesRead = imageStream.Read(buffer, 0, blockSize);
                            if (bytesRead == 0)
                            {
                                break;
                            }
                            _response.OutputStream.Write(buffer, 0, bytesRead);
                        }
                    }
                }
                catch (Exception e)
                {
                    _error = e;
                }
                finally
                {
                    _response.End();
                    SetComplete();
                }
            }
        //Generate QRCode MES-102 by Jin Song
        public static System.Drawing.Image DrawQrCode(string code)
        {
            BarcodeDraw draw = BarcodeDrawFactory.CodeQr;

            return(draw.Draw(code, 50));
        }
Exemple #25
0
        public static Image GetImageBarcode(string barcode)
        {
            BarcodeSymbology s          = BarcodeSymbology.CodeEan13;
            BarcodeDraw      drawObject = BarcodeDrawFactory.GetSymbology(s);
            var metrics = drawObject.GetDefaultMetrics(60);

            metrics.Scale = 2;
            string temp        = barcode.Remove(barcode.Length - 1, 1);
            var    img         = drawObject.Draw(temp, metrics);
            var    resultImage = new Bitmap(img.Width, img.Height + 20); // 20 is bottom padding, adjust to your text

            using (var graphics = Graphics.FromImage(resultImage))
                using (var font = new Font("Consolas", 10))
                    using (var brush = new SolidBrush(Color.Black))
                        using (var format = new StringFormat
                        {
                            Alignment = StringAlignment.Center, // Also, horizontally centered text, as in your example of the expected output
                            LineAlignment = StringAlignment.Far
                        })
                        {
                            graphics.Clear(Color.White);
                            graphics.DrawImage(img, 0, 0);
                            graphics.DrawString(barcode, font, brush, resultImage.Width / 2, resultImage.Height, format);
                        }
            //Image img = code.Draw(barcode, 20);
            //float scale = 120F/25.4F;
            //float widthImg = 37.29F;
            //float heightImg = 25.93F;
            //float heightLine = 22.85F * scale;
            //float widthLine = 0.33F* scale;
            //string encrypteBarcode = GrtEncryptBarcode(GetType(int.Parse(barcode[0].ToString())), barcode);
            ////Bitmap img = new Bitmap((int)(widthImg * scale), (int)(heightImg * scale));
            //Graphics drawing = Graphics.FromImage(img);
            //GraphicsState gs = drawing.Save();
            //drawing.PageUnit = GraphicsUnit.Pixel;
            //drawing.PageScale = 1;
            //RectangleF rect = new RectangleF(0, 0, widthImg * scale, heightImg * scale);
            //drawing.FillRectangle(new SolidBrush(Color.White), rect);
            //float curPosX = 11 * widthLine;
            //foreach (var enBar in encrypteBarcode)
            //{
            //    if (enBar == '1')
            //    {
            //        rect = new RectangleF(curPosX, 0, widthLine, heightLine);
            //        drawing.FillRectangle(new SolidBrush(Color.Black), rect);
            //    }
            //    else if (enBar == '2')
            //    {
            //        rect = new RectangleF(curPosX, 0, widthLine, heightLine + 5 * widthLine);
            //        drawing.FillRectangle(new SolidBrush(Color.Black), rect);
            //    }
            //    curPosX += widthLine;
            //}

            //curPosX = 11 * widthLine - 3.63F* scale;
            //for (int i = 0; i < barcode.Length; i++)
            //{
            //    drawing.DrawString(barcode[i].ToString(), new Font("Arial", 2.75F * scale), new SolidBrush(Color.Black), curPosX,
            //        heightLine + 0.5F * widthLine);
            //    if (i == 0)
            //    {
            //        curPosX = 14 * widthLine;
            //    }
            //    if(i != 0)
            //    {
            //        curPosX += drawing.MeasureString(barcode[i].ToString(),
            //            new Font("Arial", 2.75F * scale)).Width;
            //    }
            //}

            //drawing.Restore(gs);


            //Bitmap res = new Bitmap((int)Math.Round(widthImg), (int)Math.Round(heightImg));
            //Graphics rdrawing = Graphics.FromImage(res);
            //rdrawing.DrawImage(img, 0, 0, widthImg*scale, heightImg*scale);
            //drawing.Dispose();
            //img.Dispose();
            //rdrawing.Dispose();
            return(resultImage);
        }
        public static System.Drawing.Image DrawBarCode_AGV(string code)
        {
            BarcodeDraw draw = BarcodeDrawFactory.Code128WithChecksum;

            return(draw.Draw(code, 220, 3));
        }