Esempio n. 1
0
        public Image GetBarcode(string dataToBeEncoded, int width, int height, bool includeLabel)
        {
            Image encodeData = null;

            const AlignmentPositions align = AlignmentPositions.CENTER;
            const TYPE type = TYPE.CODE128A;

            try
            {
                b.IncludeLabel = includeLabel;
                b.Alignment    = align;

                var rotate = Enum.GetNames(typeof(RotateFlipType))[1];
                b.RotateFlipType = (RotateFlipType)Enum.Parse(typeof(RotateFlipType), rotate, true);
                b.LabelPosition  = LabelPositions.BOTTOMCENTER;

                //===== Encoding performed here =====
                encodeData = b.Encode(type, dataToBeEncoded.Trim(), Color.Black, Color.White, width, height);
                //===================================
            }//try
            catch
            {
                //MessageBox.Show(ex.Message);
            }//catch

            return(encodeData);
        }
Esempio n. 2
0
        static void GenerateBarcodeNoLable(Stream stream, string source, TYPE type = TYPE.CODE128, int imageWidth = 200, int imageHeight = 50, string strImageFormat = "jpeg", AlignmentPositions positions = AlignmentPositions.CENTER)
        {
            try
            {
                BarcodeLib.Barcode b = new BarcodeLib.Barcode();

                if (type != TYPE.UNSPECIFIED)
                {
                    b.IncludeLabel = false;
                    b.Alignment    = positions;

                    var Forecolor = "000000";
                    var Backcolor = "FFFFFF";

                    //===== Encoding performed here =====
                    System.Drawing.Image barcodeImage;
                    if (!CheckInputInSpeacial(source.Trim()))
                    {
                        barcodeImage = b.Encode(type, source.Trim(),
                                                ColorTranslator.FromHtml("#" + Forecolor),
                                                ColorTranslator.FromHtml("#" + Backcolor),
                                                imageWidth, imageHeight);
                    }
                    else
                    {
                        barcodeImage = b.Encode(type, source.Trim(),
                                                ColorTranslator.FromHtml("#" + Forecolor),
                                                ColorTranslator.FromHtml("#" + Backcolor));
                    }



                    //===================================

                    //===== Static Encoding performed here =====
                    //barcodeImage = BarcodeLib.Barcode.DoEncode(type, this.txtData.Text.Trim(), this.chkGenerateLabel.Checked, this.btnForeColor.BackColor, this.btnBackColor.BackColor);
                    //==========================================

                    //Response.ContentType = "image/" + strImageFormat;

                    switch (strImageFormat)
                    {
                    case "gif": barcodeImage.Save(stream, ImageFormat.Gif); break;

                    case "jpeg": barcodeImage.Save(stream, ImageFormat.Jpeg); break;

                    case "png": barcodeImage.Save(stream, ImageFormat.Png); break;

                    case "bmp": barcodeImage.Save(stream, ImageFormat.Bmp); break;

                    case "tiff": barcodeImage.Save(stream, ImageFormat.Tiff); break;
                    } //switch
                }     //if
            }         //try
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Esempio n. 3
0
        public static void GenerateBarcodeNoLabelWithBarWidth(Stream stream, string source, TYPE type = TYPE.CODE128, string strImageFormat = "jpeg", AlignmentPositions positions = AlignmentPositions.CENTER)
        {
            try
            {
                Barcode b = new Barcode {
                    BarWidth = 1
                };

                if (type != TYPE.UNSPECIFIED)
                {
                    b.IncludeLabel = false;
                    b.Alignment    = positions;

                    //===== Encoding performed here =====
                    Image barcodeImage;
                    if (!CheckInputInSpeacial(source.Trim()))
                    {
                        barcodeImage = b.Encode(type, source.Trim());
                    }
                    else
                    {
                        barcodeImage = b.Encode(type, source.Trim());
                    }

                    switch (strImageFormat)
                    {
                    case "gif": barcodeImage.Save(stream, ImageFormat.Gif); break;

                    case "jpeg": barcodeImage.Save(stream, ImageFormat.Jpeg); break;

                    case "png": barcodeImage.Save(stream, ImageFormat.Png); break;

                    case "bmp": barcodeImage.Save(stream, ImageFormat.Bmp); break;

                    case "tiff": barcodeImage.Save(stream, ImageFormat.Tiff); break;
                    } //switch
                }     //if
            }         //try
            catch (Exception ex)
            {
                throw;
            } //catch
        }
Esempio n. 4
0
        public byte[] Encode(TYPE iType, string StringToEncode, int Width, int Height, string rotateDegree, bool includeLabel, AlignmentPositions alignment)
        {
            this.Width        = Width;
            this.Height       = Height;
            this.Alignment    = alignment;
            this.IncludeLabel = includeLabel;
            if (includeLabel)
            {
                this.LabelPosition = LabelPositions.BOTTOMCENTER;
                this.LabelFont     = new Font(this.LabelFont.Name, 7);
            }

            if (!string.IsNullOrEmpty(rotateDegree))
            {
                if (rotateDegree.Equals("90"))
                {
                    this.RotateFlipType = System.Drawing.RotateFlipType.Rotate90FlipNone;
                }
            }
            else
            {
                this.RotateFlipType = System.Drawing.RotateFlipType.RotateNoneFlipNone;
            }
            Image        x  = Encode(iType, StringToEncode);
            MemoryStream ms = new MemoryStream();

            x.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
            ms.Close();
            return(ms.ToArray());
        }
Esempio n. 5
0
        public Image Encode(TYPE iType, string StringToEncode, Color ForeColor, Color BackColor, int Width, int Height, AlignmentPositions alignment, RotateFlipType rotateFlipType, bool includeLabel, LabelPositions labelPosition)
        {
            Encoded_Type        = iType;
            Raw_Data            = StringToEncode;
            this.ForeColor      = ForeColor;
            this.BackColor      = BackColor;
            this.Width          = Width;
            this.Height         = Height;
            this.Alignment      = alignment;
            this.RotateFlipType = rotateFlipType;
            this.IncludeLabel   = includeLabel;

            this.LabelPosition = labelPosition;
            return(Encode());
        }