C#调用ThoughtWorks.QRCode.dll生成带参数二维码

ThoughtWorks.QRCode.Codec.QRCodeEncoder encoder = new QRCodeEncoder();
        encoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;//编码方式(注意:BYTE能支持中文,ALPHA_NUMERIC扫描出来的都是数字)
        encoder.QRCodeScale = 4;//大小(值越大生成的二维码图片像素越高)
         encoder.QRCodeVersion = 0;//版本(注意:设置为0主要是防止编码的字符串太长时发生错误)
         encoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;//错误效验、错误更正(有4个等级)
  String qrdata = "二维码信息";
System.Drawing.Bitmap bp = encoder.Encode(qrdata.ToString(), Encoding.GetEncoding("GB2312"));
            Image image = bp;
            pictureBox1.Image = bp;
保存二维码图片:
SaveFileDialog sf = new SaveFileDialog();
            sf.Title = "选择保存文件位置";
            sf.Filter = "保存图片(*.jpg) |*.jpg|所有文件(*.*) |*.*";
            //设置默认文件类型显示顺序
            sf.FilterIndex = 1;
            //保存对话框是否记忆上次打开的目录
            sf.RestoreDirectory = true;
            if (sf.ShowDialog() == DialogResult.OK)
            {
                Image im = this.pictureBox1.Image;
                //获得文件路径
                string localFilePath = sf.FileName.ToString();
                if (sf.FileName != "")
                {
                   string fileNameExt = localFilePath.Substring(localFilePath.LastIndexOf("\\") + 1);//获取文件名,不带路径
                   // newFileName = fileNameExt+DateTime.Now.ToString("yyyyMMdd")  ;//给文件名后加上时间
                   string FilePath = localFilePath.Substring(0, localFilePath.LastIndexOf("."));  //获取文件路径,带文件名,不带后缀
                    string fn = sf.FileName;
                    pictureBox1.Image.Save(FilePath +"-"+ DateTime.Now.ToString("yyyyMMdd") + ".jpg");
                   
                }
}
 //解析二维码信息
  // QRCodeDecoder decoder = new QRCodeDecoder();
  //  String decodedString = decoder.decode(new QRCodeBitmapImage(new Bitmap(pictureBox1.Image)));
   //this.label3.Text = decodedString; 

你可能感兴趣的:(.net开发,二维码,.net,web,c#)