private BarcodeSettingParameter GetParameter() { var para = new BarcodeSettingParameter(); para.UserControl = this; para.Content = tbContent.Text; para.PicSize = (cmbSizeList.SelectedItem as CmbDataItem)?.Value ?? 0; return(para); }
/// <summary> /// 生成条形码 /// </summary> /// <param name="para"></param> /// <returns></returns> private Bitmap GetBarcodeBitmap(BarcodeSettingParameter para) { QrCodeEncodingOptions option = new QrCodeEncodingOptions() { CharacterSet = "utf8bom", Width = 50, Height = para.PicSize }; BarcodeWriter bw = new BarcodeWriter() { Options = option, Format = BarcodeFormat.CODABAR }; return(ImageTool.ConvertBitmapTo8(bw.Write(para.Content))); }
public void DealBarcodeSetting(string guid, BarcodeSettingParameter para) { try { this._id = guid; //查找是否存在这个组件 var pmjData = _pmjDataList.FirstOrDefault(item => item.Id == guid); //生成bitmap图片 var bitmap = GetBarcodeBitmap(para); Console.WriteLine($"二维码, width:{bitmap.Width} height:{bitmap.Height} format:{bitmap.PixelFormat}"); 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); } }