Beispiel #1
0
        public void CreateDataMatrixCode(Worksheet clsWorksheet, Range range, string path)
        {
            for (int row = 2; row < range.Rows.Count; row++)
            {
                dynamic cellValue   = ((Range)clsWorksheet.Cells[row, 1]).Value;
                string  orderNumber = Convert.ToString(cellValue);

                DataMatrix datamatrix = new DataMatrix();
                datamatrix.Data        = orderNumber;
                datamatrix.DataMode    = DataMatrixDataMode.ASCII;
                datamatrix.ImageFormat = System.Drawing.Imaging.ImageFormat.Bmp;
                datamatrix.drawBarcode($"{path}\\{orderNumber}.bmp");

                Range       oRange    = range.Cells[row, 1];
                float       Left      = (float)((double)oRange.Left + 35);
                float       Top       = (float)((double)oRange.Top + 3);
                const float ImageSize = 13;
                FileInfo    file      = new FileInfo($"{path}\\{orderNumber}.bmp")
                {
                    IsReadOnly = false
                };
                FileInfo pathFileInfo = new FileInfo(path)
                {
                    IsReadOnly = false
                };

                string bmpPath = file.Name;
                clsWorksheet.Shapes.AddPicture($"{path}\\{bmpPath}",
                                               Microsoft.Office.Core.MsoTriState.msoFalse,
                                               Microsoft.Office.Core.MsoTriState.msoCTrue, Left, Top, ImageSize, ImageSize);
                File.Delete($"{path}\\{orderNumber}.bmp");
            }
        }
Beispiel #2
0
        /// <summary>
        /// Datamatrix 데이터 받아서 이미지로 변환
        /// </summary>
        /// <param name="data"></param>
        /// <param name="icon"></param>
        /// <returns></returns>
        public Image RenderDataMatrix(string data, Bitmap icon = null)
        {
            Image      img2;
            DataMatrix datamatrix = new DataMatrix();

            // Barcode data to encode
            datamatrix.Data = data;
            // Data Matrix data mode
            datamatrix.DataMode = DataMatrixDataMode.ASCII;
            // Data Matrix format mode
            datamatrix.FormatMode = DataMatrixFormatMode.Format_16X16;

            /*
             * Barcode Image Related Settings
             */
            // Unit of meature for all size related setting in the library.
            datamatrix.UOM = UnitOfMeasure.PIXEL;
            // Bar module size (X), default is 3 pixel;
            datamatrix.X = 3;
            // Barcode image left, right, top, bottom margins. Defaults are 0.
            datamatrix.LeftMargin   = 0;
            datamatrix.RightMargin  = 0;
            datamatrix.TopMargin    = 0;
            datamatrix.BottomMargin = 0;
            // Image resolution in dpi, default is 72 dpi.
            datamatrix.Resolution = 72;
            // Created barcode orientation.
            //4 options are: facing left, facing right, facing bottom, and facing top
            datamatrix.Rotate = Rotate.Rotate0;

            // Generate data matrix and encode barcode to gif format
            // datamatrix.ImageFormat = System.Drawing.Imaging.ImageFormat.Gif;
            img2 = datamatrix.drawBarcode();

            return(img2);
        }
        private void btnGen_Click(object sender, EventArgs e)
        {
            Options opt     = (Options)cbType.SelectedItem;
            string  strCont = tbCon.Text.Trim();
            string  pic     = "D:\\Temp\\Barcode_" + DateTime.Now.ToString("MMddHHmmss") + ".jpg";

            picbc.Invalidate();
            if (strCont != "")
            {
                if (opt == null)
                {
                    MessageBox.Show("Please choice \"Label Type\"!!");
                }
                else
                {
                    switch (opt.Value)
                    {
                    case 1:
                    case 2:
                        Linear lb = new Linear();
                        if (opt.Value == 1)
                        {
                            lb.Type = BarcodeType.CODE39;
                            lb.Data = strCont.ToUpper();
                        }
                        else
                        {
                            lb.Type = BarcodeType.CODE128;
                            lb.Data = strCont;
                        }
                        if (cbox.Checked)
                        {
                            lb.ShowText = true;
                        }
                        else
                        {
                            lb.ShowText = false;
                        }
                        lb.BearerBarWidth = 2;
                        lb.BarHeight      = 50;
                        lb.drawBarcode(pic);

                        break;

                    case 3:
                        PDF417 p = new PDF417();
                        p.Data    = strCont;
                        p.Columns = 5;
                        p.Rows    = 10;
                        p.drawBarcode(pic);
                        break;

                    case 4:
                        DataMatrix dm = new DataMatrix();
                        dm.ModuleSize   = 8;
                        dm.RightMargin  = 6;
                        dm.LeftMargin   = 6;
                        dm.TopMargin    = 6;
                        dm.BottomMargin = 6;
                        dm.drawBarcode(pic);
                        break;

                    case 5:
                        QRCode qr = new QRCode();
                        qr.ModuleSize   = 7;
                        qr.RightMargin  = 3;
                        qr.LeftMargin   = 3;
                        qr.TopMargin    = 3;
                        qr.BottomMargin = 3;
                        qr.drawBarcode(pic);
                        break;

                    default:
                        break;
                    }
                    if (File.Exists(pic))
                    {
                        Bitmap bmp = new Bitmap(pic);
                        try
                        {
                            picbc.Width  = bmp.Width;
                            picbc.Height = bmp.Height;
                            int pw = (panel1.Width - picbc.Width) / 2;
                            int ph = (panel1.Height - picbc.Height) / 2;
                            picbc.Left  = pw;
                            picbc.Top   = ph;
                            picbc.Image = bmp;
                        }
                        catch (Exception err)
                        {
                            MessageBox.Show(err.Message);
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("Conten is empty!!");
            }
        }