コード例 #1
0
        private void comboBoxProducts_SelectedIndexChanged(object sender, EventArgs e)
        {
            product_desc product = (product_desc)comboBoxProducts.SelectedItem;

            string serial = SerialNumber.BuildSerial(product.Id, 1);

            textBoxData.Text = serial;
        }
コード例 #2
0
        public Form1()
        {
            InitializeComponent();

            string serial_number = SerialNumber.BuildSerial(5, 1);

            _dic_error_correction.Add('L', ErrorCorrectionLevel.L); // 7%
            _dic_error_correction.Add('M', ErrorCorrectionLevel.M); // 15%
            _dic_error_correction.Add('Q', ErrorCorrectionLevel.Q); // 25%
            _dic_error_correction.Add('H', ErrorCorrectionLevel.H); // 30%

            _dic_quite_zone.Add('0', QuietZoneModules.Zero);
            _dic_quite_zone.Add('2', QuietZoneModules.Two);
            _dic_quite_zone.Add('4', QuietZoneModules.Four);
        }
コード例 #3
0
        void encodeToPictureBox()
        {
            String data = textBoxData.Text;
            ErrorCorrectionLevel correction_level = _dic_error_correction[comboBoxCorrectionLevel.Text[0]];
            QuietZoneModules     quite_zone       = _dic_quite_zone[comboBoxQuiteZone.Text[0]];


            QrEncoder qrEncoder = new QrEncoder(correction_level);
            QrCode    qrCode    = qrEncoder.Encode(data);

            float dpi        = (float)numericUpDownDPI.Value;
            float pdpi       = pictureBox1.CreateGraphics().DpiX;
            float ratio      = 1;
            float dim_inches = (float)numericUpDownSize.Value;

            if (dim_inches == 0)
            {
                // Full screen
                int side = pictureBox1.Height;
                //side = 100; //=> 1"
                if (pictureBox1.Height > pictureBox1.Width)
                {
                    side = pictureBox1.Width;
                }
                dim_inches = side / dpi;
            }
            else
            {
                ratio = pdpi / dpi;
                if (comboBoxSizeUnit.Text == "mm")
                {
                    dim_inches = (float)Length.FromMillimeters(dim_inches).Inches;
                }
            }

            //_bitmap_for_print = encodeToBitMap(data, dim, dpi, dpi, correction_level, quite_zone);

            product_desc product_desc        = (product_desc)this.comboBoxProducts.SelectedItem;
            int          product_id          = product_desc.Id;
            int          start_serial_number = 0;
            int          number_of_labels    = 6;


            _bitmaps_for_print = new Bitmap[number_of_labels];
            for (int l = 0; l < number_of_labels; l++)
            {
                string serial = SerialNumber.BuildSerial(product_id, start_serial_number++);

                Bitmap bitmap = encodeToBitMap(
                    serial, dim_inches, dpi, dpi, correction_level, quite_zone);

                _bitmaps_for_print[l] = bitmap;
            }


            Bitmap _bitmap_for_print = _bitmaps_for_print[0];

            /*
             * DrawingBrushRenderer dRenderer = new DrawingBrushRenderer(iSizeCal,
             *  System.Windows.Media.Brushes.Black, System.Windows.Media.Brushes.White);
             * MemoryStream mem_stream = new MemoryStream();
             * dRenderer.WriteToStream(qrCode.Matrix, ImageFormatEnum.BMP, mem_stream);
             * _bitmap_for_print = new Bitmap(mem_stream);
             * _bitmap_for_print.SetResolution(dpi, dpi);
             * */

            float  zoom_factor = (float)numericUpDownZoomFactor.Value;
            Bitmap pbitmap     = new Bitmap(_bitmap_for_print,
                                            (int)(_bitmap_for_print.Width * ratio * zoom_factor), (int)(_bitmap_for_print.Height * ratio * zoom_factor));

            //this.pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
            this.pictureBox1.Image = pbitmap;


            // A different way to do the same.  Just incase the bitmap.SetResolution function does not work
            //System.Windows.Point dpipoint = new System.Windows.Point(300, 300);
            //BitmapSource bitmapsource = dRenderer.WriteToBitmapSource(qrCode.Matrix, dpipoint);
            //MemoryStream outStream = new MemoryStream();
            //BitmapEncoder bitmapencoder = new BmpBitmapEncoder();
            //BitmapFrame bitmapframe = BitmapFrame.Create(bitmapsource);
            //bitmapencoder.Frames.Add(bitmapframe);
            //bitmapencoder.Save(outStream);
            //Bitmap bitmap2 = new System.Drawing.Bitmap(outStream);

            //PDF417Generator p = new PDF417Generator();
            //Bitmap bitmap2 = p.GeneratePDF417Code(pictureBox2.Height / 4, pictureBox2.Width / 2, textBoxData.Text);
            //bitmap2.SetResolution(300,300);
            //this.pictureBox2.Image = bitmap2;

            pictureBox2.Refresh();
        }