示例#1
0
        private void UpdateQRCodePanel(object sender, EventArgs e)
        {
            btnSave.Enabled = false;
            qrcodePanel.Controls.Clear();

            if (string.IsNullOrEmpty(txtData.Text))
            {
                return;
            }

            ErrorCorrectionLevel ecLevel = (ErrorCorrectionLevel)cmbErrorCorrectionLevel.SelectedItem;
            int    version = (int)cmbMaxVersion.SelectedItem;
            bool   allowStructuredAppend = chkStructuredAppend.Checked;
            string charsetName           = (string)cmbCharset.SelectedItem;
            int    moduleSize            = (int)nudModuleSize.Value;

            Symbols symbols = new Symbols(ecLevel, version, allowStructuredAppend, charsetName);

            try
            {
                symbols.AppendText(txtData.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }

            foreach (Symbol symbol in symbols)
            {
                Image      image      = symbol.GetImage(moduleSize);
                PictureBox pictureBox = new PictureBox()
                {
                    Size  = image.Size,
                    Image = image
                };
                qrcodePanel.Controls.Add(pictureBox);
            }

            btnSave.Enabled = txtData.TextLength > 0;
        }
示例#2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            string baseName;
            bool   isMonochrome;
            string ext;

            string[] filters =
            {
                "Monochrome Bitmap(*.bmp)|*.bmp",
                "24-bit Bitmap(*.bmp)|*.bmp",
                "SVG(*.svg)|*.svg"
            };

            using (var fd = new SaveFileDialog())
            {
                fd.Filter = String.Join("|", filters);

                if (fd.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                isMonochrome = fd.FilterIndex == 1;
                baseName     = Path.Combine(
                    Path.GetDirectoryName(fd.FileName),
                    Path.GetFileNameWithoutExtension(fd.FileName));

                switch (fd.FilterIndex)
                {
                case 1:
                case 2:
                    ext = FileExtension.BITMAP;
                    break;

                case 3:
                    ext = FileExtension.SVG;
                    break;

                default:
                    throw new InvalidOperationException();
                }
            }

            ErrorCorrectionLevel ecLevel = (ErrorCorrectionLevel)cmbErrorCorrectionLevel.SelectedItem;
            int    version = (int)cmbMaxVersion.SelectedItem;
            bool   allowStructuredAppend = chkStructuredAppend.Checked;
            string charsetName           = (string)cmbCharset.SelectedItem;
            int    moduleSize            = (int)nudModuleSize.Value;

            Symbols symbols = new Symbols(ecLevel, version, allowStructuredAppend, charsetName);

            try
            {
                symbols.AppendText(txtData.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }

            for (int i = 0; i < symbols.Count; ++i)
            {
                string filename;

                if (symbols.Count == 1)
                {
                    filename = baseName + ext;
                }
                else
                {
                    filename = baseName + "_" + (i + 1).ToString() + ext;
                }

                switch (ext)
                {
                case FileExtension.BITMAP:
                    symbols[i].SaveBitmap(filename, moduleSize, isMonochrome);
                    break;

                case FileExtension.SVG:
                    symbols[i].SaveSvg(filename, moduleSize);
                    break;

                default:
                    throw new InvalidOperationException();
                }
            }
        }