Ejemplo n.º 1
0
        /// <summary>
        /// 生成二维码的图片
        /// </summary>
        /// <param name="para"></param>
        /// <returns></returns>
        private Bitmap GetQrcodeBitmap(QrcodeSettingParameter para)
        {
            QrCodeEncodingOptions option = new QrCodeEncodingOptions()
            {
                CharacterSet = para.QrcodeType,
                Width        = para.PicSize,
                Height       = para.PicSize
            };
            BarcodeWriter bw = new BarcodeWriter()
            {
                Options = option, Format = BarcodeFormat.QR_CODE
            };

            return(ImageTool.ConvertBitmapTo8(bw.Write(para.Content)));
        }
Ejemplo n.º 2
0
        private QrcodeSettingParameter GetParameter()
        {
            var para = new QrcodeSettingParameter();

            para.Content = tbContent.Text;
            if (string.IsNullOrEmpty(para.Content))
            {
                para.Content = "empty";
            }

            para.PicSize     = (cmbSizeList.SelectedItem as CmbDataItem)?.Value ?? 0;
            para.QrcodeType  = (cmbTypeList.SelectedItem as CmbDataItem)?.Name;
            para.UserControl = this;
            return(para);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 对二维码的编辑信息进行处理
        /// </summary>
        /// <param name="guid"></param>
        /// <param name="para"></param>
        public void DealQrcodeSetting(string guid, QrcodeSettingParameter para)
        {
            try
            {
                this._id = guid;
                //查找是否存在这个组件
                var pmjData = _pmjDataList.FirstOrDefault(item => item.Id == guid);
                //生成bitmap图片
                var bitmap = GetQrcodeBitmap(para);
                Console.WriteLine($"二维码, width:{bitmap.Width}  height:{bitmap.Height}");
                if (null == pmjData)
                {
                    pmjData          = new PmjData();
                    pmjData.Id       = guid;
                    pmjData.DataType = EnumPmjData.二维码;
                    var picture = new PictureBox();
                    picture.Name    = guid;
                    pmjData.Control = picture;
                    //设置组件的图片
                    SetPictureBoxImage(picture, bitmap);
                    picture.DoubleClick += SetPmjDataClick;
                    panelTest.Controls.Add(picture);
                    pmjData.DataSource = para;
                    //设置可以移动
                    SetItemEvent(picture);
                    _pmjDataList.Add(pmjData);
                }
                else
                {
                    var pic = pmjData.Control as PictureBox;
                    //销毁原来的bitmap数据
                    (pic.Image as Bitmap)?.Dispose();
                    SetPictureBoxImage(pic, bitmap);
                    //有可能会越界,如果越界的话,就直接重置top的数值
                    ResetLocation(pic);

                    pmjData.DataSource = para;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }