编写读取条形码的代码,并进行调试

 

        private void button8_Click(object sender, EventArgs e)
        {
            DecodingOptions decodeOption = new DecodingOptions();
            decodeOption.PossibleFormats = new List<BarcodeFormat>() { BarcodeFormat.EAN_13 };
            //读取条形码
            BarcodeReadr br = new BarcodeReader();
            br.Options = decodeOption;
            Result result = br.Decode(pictureBox2.Image as Bitmap);
            if (result == null)
            {
                MessageBox.Show("读取失败");
            }
            else
            {
                //读取成功
                string xs = "";
                textBox3.Text = result.Text;
                xs = textBox3.Text;
                MessageBox.Show("一维码:"+xs+"","读取成功",MesageBoxButtons.OK,MessageBoxIcon.Asterisk);
            }
        }

        //生成二维码-生成
        private void button3_Click(object sender, EventArgs e)
        {
            //设置QR二维码的规格
            ZXing.QrCode.QrCodeEncodingOptions qrEncodeOption = new ZXing.QrCode.QrCodeEncodingOptions();
            //设置编码格式,否则中文乱码
            qrEncodeOption.CharacterSet = "UTF-8";
            //设置宽和高
            qrEncodeOption.Height = 200;
            qrEncodeOption.Width = 200;
            //设置周围空白边距
            qrEncodeOption.Margin = 1;
            ZXing.BarcodeWriter wr = new BarcodeWriter();
            //二维码
            wr.Format = BarcodeFormat.QR_CODE;
            wr.Options = qrEncodeOption;
            //生成二维码
            Bitmap image = wr.Write(textBox4.Text);
            //显示
            pictureBox3.Image = image;
        }

 

posted @ 2018-12-19 20:06  chjch  阅读(112)  评论(0编辑  收藏  举报