CSharp生成二维条码的步骤

一、Demo和控件下载

打开http://www.FzBzc.com/CSharp.html下载 客户端演示DEMO到本地,并进行解压打开。

DEMO采用VS2010开发,需要FrameWork4.0开发。

二、类库引用

将下载的类库COPY到开发目录下,点击VS下的“引用”右键,选择“添加引用”,将类库引用到程序中。

三、编码参数设置

根据分页参数设置,将设置的参数写入对应条码参数对象中。

private EncodingOptions GetOption(int nType = 0)

        {

 EncodingOptions options;

            if(nType == 0)    //PDF417

            {

                FzBozc.PDF417.PDF417EncodingOptions pdf =

                    newFzBozc.PDF417.PDF417EncodingOptions();

                pdf.Aspect =DDL_Aspect.SelectedValue;

                pdf.Compact =Chk_Compact.Checked;

                pdf.Cols =ToInt(TB_Cols.Text);

                pdf.Rows = ToInt(TB_Rows.Text);

                pdf.XScale =ToInt(DDL_XScale.SelectedValue);

                pdf.YScale =ToInt(DDL_YScale.SelectedValue);

                pdf.ErrorCorrection =(FzBozc.PDF417.Internal.PDF417ErrorLevel)ToInt(DDL_EccPDF.SelectedValue);

                options = pdf;

            }

            elseif (nType == 1)           //Qr_Code

            {

                FzBozc.QrCode.QrCodeEncodingOptions qr =new FzBozc.QrCode.QrCodeEncodingOptions();

                qr.MdScale =ToInt(DDL_Scale.SelectedValue);

                if(DDL_EccQR.SelectedValue =="L")qr.ErrorCorrection = FzBozc.QrCode.Internal.QrErrorLevel.L;

                elseif (DDL_EccQR.SelectedValue =="M") qr.ErrorCorrection =FzBozc.QrCode.Internal.QrErrorLevel.M;

                elseif (DDL_EccQR.SelectedValue =="H") qr.ErrorCorrection =FzBozc.QrCode.Internal.QrErrorLevel.H;

                elseqr.ErrorCorrection = FzBozc.QrCode.Internal.QrErrorLevel.Q;

                options = qr;

            }

            elseif (nType == 2)    //DataMatrix

            {

                FzBozc.Datamatrix.DatamatrixEncodingOptions dm =new FzBozc.Datamatrix.DatamatrixEncodingOptions();

                dm.MdScale =ToInt(DDL_Scale.SelectedValue);

                options = dm;

            }

            else        //Aztec

            {

                FzBozc.Aztec.AztecEncodingOptions azt =new FzBozc.Aztec.AztecEncodingOptions();

                azt.MdScale =ToInt(DDL_Scale.SelectedValue);

                azt.ErrorCorrection =ToInt(TB_EccPercent.Text);

                options = azt;

            }

            options.Width =ToInt(TB_Width.Text);

            options.Height = ToInt(TB_Height.Text);

            return(EncodingOptions)options;

四. 生成条码

根据参数设置和条码内容,生成条码。

条码需要保存到服务端对应的目录下,如“BarImage”目录

网站目录要具有写入权限。

protectedvoid Btn_Create_Click(object sender,EventArgse)

  {

           try

            {

               intk = DDL_BarType.SelectedIndex;

               BarcodeFormatfmtBarCode = BarcodeFormat.PDF_417;

               if(k == 1) fmtBarCode = BarcodeFormat.QR_CODE;

               if(k == 2) fmtBarCode = BarcodeFormat.DATA_MATRIX;

                if(k == 3) fmtBarCode =BarcodeFormat.AZTEC;

               EncodingOptionsBarOptions = GetOption(k);

               varwriter = new BarcodeWriter

                {

                    Format = fmtBarCode,

                    Options = BarOptions

                };

                System.Drawing.Image img= writer.Write(TB_Info.Text);

               //输出图像

               stringfilename = Guid.NewGuid().ToString() +".jpg";

               stringfilepath =Server.MapPath(@"~\BarImage")+"\\" + filename;

                System.IO.FileStream fs =newSystem.IO.FileStream(filepath, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write);

                img.Save(fs,System.Drawing.Imaging.ImageFormat.Jpeg);

                fs.Close();

               

                pictBar.ImageUrl ="BarImage/"+ filename;               

                pictBar.Width = img.Width;

                pictBar.Height = img.Height;

                img.Dispose();

            }

           catch(Exception ex )

            {

                Response.Write("<script>alert('"+ex.Message+"')</script>");

            }

        }

若有开发问题咨询 QQ:409487486 (纯技术交流,非诚勿扰)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值