C# 实现条码图片自动生成功能
作者:C/S框架网  发布日期:2011/06/10 18:32:46
C# 实现条码图片自动生成功能


BarCodeControl,v 1.5.0.0
版权所有 (C) Cobainsoft 2005 - 2007

需要引用Barcode.dll组件,在Debug目录下,生成的条码效果图如下:

贴图图片



C# Code:

private void btnDO_Click(object sender, EventArgs e)
{
   string barcode = "";
   
   //打开生成条码窗体
   Image img = frmBarcodeGenerator.Execute(out barcode);
   
   if (img != null)
   {
      img.Save("c:\\ttt_.bmp", ImageFormat.Bmp); //存到临时文件
      byte[] bs = this.GetImageBytes("c:\\ttt_.bmp");//转换为byte数组
      
      DataRow newBarcode = (gridControl1.DataSource as DataTable).NewRow();
      (gridControl1.DataSource as DataTable).Rows.Add(newBarcode);
      
      newBarcode["Barcode"] = barcode;
      newBarcode["BarcodeImage"] = bs;
      
      gridView1.UpdateCurrentRow();
      gridView1.FocusedColumn.Width = 1; //自动缩放
      gridView1.FocusedColumn.Width -= 1;
   }
}


//来源:C/S框架网(www.csframework.com) QQ:1980854898



组合条码图片:


C# Code:

private void PreviewKJ()
{
   barcodeControl2.Data = textEdit16.Text; //给条码控制指定编号
   label31.Visible = checkEdit1.Checked;
   label32.Text = textEdit13.Text;
   label35.Text = textEdit17.Text;
   
   //创建白底条码空白图片
   System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(pictureBox3.Width, pictureBox3.Height);
   DrawBackgroundColor(bmp);
   
   Rectangle rec = new Rectangle(barcodeControl2.Location, barcodeControl2.Size);
   barcodeControl2.DrawToBitmap(bmp, rec); //将条码画到空白图片
   
   rec = new Rectangle(label32.Location, label32.Size);
   label32.DrawToBitmap(bmp, rec); //将附加信息画到空白图片
   
   rec = new Rectangle(label35.Location, label35.Size);
   label35.DrawToBitmap(bmp, rec);//将附加信息画到空白图片
   
   if (checkEdit1.Checked)
   {
      rec = new Rectangle(label31.Location, label31.Size);
      label31.DrawToBitmap(bmp, rec);//将附加信息画到空白图片
   }
   
   picOutput.Size = pictureBox3.Size;
   picOutput.Image = bmp;
   picOutput.Height = 10;
   
   _retBarcode = textEdit16.Text;//条码编号
}

//来源:C/S框架网(www.csframework.com) QQ:1980854898




点击下载附件 点击下载附件 (如下载失败,请邮件通知我们寄回给您,或QQ:23404761留言.)
上一篇 下一篇