下载地址:http://zxingnet.codeplex.com/

zxing.net是.net平台下编解条形码和二维码的工具,使用非常方便。

首先下载二进制dll文件,引入工程;

代码:

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using ZXing.QrCode;
  9. using ZXing;
  10. using ZXing.Common;
  11. using ZXing.Rendering;
  12. namespace zxingTest
  13. {
  14. public partial class Form1 : Form
  15. {
  16. EncodingOptions options = null;
  17. BarcodeWriter writer = null;
  18. public Form1()
  19. {
  20. InitializeComponent();
  21. options = new QrCodeEncodingOptions
  22. {
  23. DisableECI = true,
  24. CharacterSet = "UTF-8",
  25. Width = pictureBoxQr.Width,
  26. Height = pictureBoxQr.Height
  27. };
  28. writer = new BarcodeWriter();
  29. writer.Format = BarcodeFormat.QR_CODE;
  30. writer.Options = options;
  31. }
  32. private void buttonQr_Click(object sender, EventArgs e)
  33. {
  34. if (textBoxText.Text == string.Empty)
  35. {
  36. MessageBox.Show("输入内容不能为空!");
  37. return;
  38. }
  39. Bitmap bitmap = writer.Write(textBoxText.Text);
  40. pictureBoxQr.Image = bitmap;
  41. }
  42. }
  43. }

效果:


 将字符编码时可以指定字符格式;默认为ISO-8859-1英文字符集,但一般移动设备常用UTF-8字符集编码,

可以通过QrCodeEncodingOptions设置编码方式。

如果要生成其他zxing支持的条形码,只要修改BarcodeWriter.Format就可以了。

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using ZXing.QrCode;
  9. using ZXing;
  10. using ZXing.Common;
  11. using ZXing.Rendering;
  12. namespace zxingTest
  13. {
  14. public partial class Form1 : Form
  15. {
  16. EncodingOptions options = null;
  17. BarcodeWriter writer = null;
  18. public Form1()
  19. {
  20. InitializeComponent();
  21. options = new EncodingOptions
  22. {
  23. //DisableECI = true,
  24. //CharacterSet = "UTF-8",
  25. Width = pictureBoxQr.Width,
  26. Height = pictureBoxQr.Height
  27. };
  28. writer = new BarcodeWriter();
  29. writer.Format = BarcodeFormat.ITF;
  30. writer.Options = options;
  31. }
  32. private void buttonQr_Click(object sender, EventArgs e)
  33. {
  34. if (textBoxText.Text == string.Empty)
  35. {
  36. MessageBox.Show("输入内容不能为空!");
  37. return;
  38. }
  39. Bitmap bitmap = writer.Write(textBoxText.Text);
  40. pictureBoxQr.Image = bitmap;
  41. }
  42. }
  43. }

效果:


 输入字符串需要符合编码的格式,不然会报错。
解码方式:
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using ZXing.QrCode;
  9. using ZXing;
  10. using ZXing.Common;
  11. using ZXing.Rendering;
  12. namespace zxingTest
  13. {
  14. public partial class Form1 : Form
  15. {
  16. BarcodeReader reader = null;
  17. public Form1()
  18. {
  19. InitializeComponent();
  20. reader = new BarcodeReader();
  21. }
  22. private void Form1_DragEnter(object sender, DragEventArgs e)//当拖放进入窗体
  23. {
  24. if (e.Data.GetDataPresent(DataFormats.FileDrop))
  25. e.Effect = DragDropEffects.Copy;    //显示拷贝效应
  26. else
  27. e.Effect = DragDropEffects.None;
  28. }
  29. private void Form1_DragDrop(object sender, DragEventArgs e) //当拖放放在窗体上
  30. {
  31. string[] fileNames = (string[])e.Data.GetData(DataFormats.FileDrop, false); //获取文件名
  32. if (fileNames.Length > 0)
  33. {
  34. pictureBoxPic.Load(fileNames[0]);   //显示图片
  35. Result result = reader.Decode((Bitmap)pictureBoxPic.Image); //通过reader解码
  36. textBoxText.Text = result.Text; //显示解析结果
  37. }
  38. }
  39. }
  40. }


 

C#利用zxing.net操作二维码和条形码的更多相关文章

  1. 基于Asp.Net Core,利用ZXing来生成二维码的一般流程

    本文主要介绍如何在.net环境下,基于Asp.Net Core,利用ZXing来生成二维码的一般操作.对二维码工作原理了解,详情见:https://blog.csdn.net/weixin_36191 ...

  2. 【VB.NET】利用 ZXing.Net 生成二维码(支持自定义LOGO)

    有任何疑问请去我的新博客提出 https://blog.clso.fun/posts/2019-03-03/vb-net-zxing-net-qr-maker.html ZXing .NET 的项目主 ...

  3. C# .Net 使用zxing.dll生成二维码,条形码

    public static string GetBarcode(string format, string value, int? width, int? height)        {       ...

  4. Android ZXing 二维码、条形码扫描介绍

    本帖最后由 Shims 于 2013-11-9 12:39 编辑 最近公司的Android项目需要用到摄像头做条码或二维码的扫描,Google一下,发现一个开源的 ZXing项目.它提供二维码和条形码 ...

  5. 使用zxing生成解析二维码

    1. 前言 随着移动互联网的发展,我们经常在火车票.汽车票.快餐店.电影院.团购网站以及移动支付等各个场景下见到二维码的应用,可见二维码以经渗透到人们生活的各个方面.条码.二维码以及RFID被人们应用 ...

  6. 二维码、条形码扫描——使用Google ZXing

    我在项目中用到了二维码扫描的技术,用的是Google提供的ZXing开源项目,它提供二维码和条形码的扫描.扫描条形码就是直接读取条形码的内容,扫描二维码是按照自己指定的二维码格式进行编码和解码. 可以 ...

  7. 二维码之zxing仿新浪微博二维码

    在前言中最后部分,提到了二维码开发工具资源ZXing.网上有它最新1.7版的源码,感兴趣的可以下载下来看看,要打包生成core比较麻烦,网上有相关教程.嫌麻烦的朋友,可以去我的资源里下载Java版的c ...

  8. C# ZXing.Net生成二维码、识别二维码、生成带Logo的二维码(二)

    1.使用ZXint.Net生成带logo的二维码 /// <summary> /// 生成带Logo的二维码 /// </summary> /// <param name ...

  9. Android二维码开源项目zxing用例简化和生成二维码、条形码

    上一篇讲到:Android二维码开源项目zxing编译,编译出来后有一个自带的測试程序:CaptureActivity比較复杂,我仅仅要是把一些不用的东西去掉,用看起来更方便,二维码和条形码的流行性自 ...

随机推荐

  1. 重启oracle数据库的操作方法

    在实际的应用中,有时候工作数据库需要重新启动.本文介绍了一个特别实用的操作步骤,希望对大家有所帮助. 1. 停应用层的各种程序 2. 停Oralce的监听进程 $ lsnrctl stop 3. 在独 ...

  2. SQL 递归找查所有子节点及所有父节

    在SQL的树型结构中,很多时候,知道某一节点的值,需要查找该节点的所有子节点(包括多级)的功能,这时就需要用到如下的用户自定义函数. 表结构如下: ID int Dep_Type int Dep_Co ...

  3. STL标准库-仿函数与仿函数适配器

    技术在于交流.沟通,本文为博主原创文章转载请注明出处并保持作品的完整性 概要: 1.仿函数 2.bind2nd() 3.not1() 4.bind() 仿函数的实现:声明一个类,重载它的operato ...

  4. 分析:新建短信,当我们接受人RecipientsEditor中输入+86的时候,系统会自动在+86后加入空格

    我们可以认为这是一个很人性的格式化操作,在ComposeMessageActivity中系统在调用initRecipientsEditor()方法对联系人进行初始化的时候调用了 PhoneNumber ...

  5. Apache Tomcat/6.0.39如何配置连接mysql,JDBC:mysql-connector-java-5.1.30-bin.jar-成功连接心得

    http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html 前提:开启TOMCAT,MYsql MySQL ...

  6. dependencies与dependencyManagement的区(转自:http://blog.csdn.net/liutengteng130/article/details/46991829)

    在上一个项目中遇到一些jar包冲突的问题,之后还有很多人分不清楚dependencies与dependencyManagement的区别,本篇文章将这些区别总结下来. 1.DepencyManagem ...

  7. C# 历史曲线控件 基于时间的曲线控件 可交互的高级曲线控件 HslControls曲线控件使用教程

    本篇博客主要对 HslControls 中的曲线控件做一个详细的教程说明,大家可以根据下面的教程开发出高质量的曲线控件 Prepare 先从nuget下载到组件,然后就可以使用组件里的各种组件信息了. ...

  8. liunx系统和其它的基本命令

    1.su   更换用户 2.sudo   管理员权限 3.PATH 4.sudo shutdown -h now   现在关机 sudo shutdown -r now   现在重启 5.kill   ...

  9. 拒绝了对对象 '****'(数据库 '******',所有者 '***')的 SELECT 权限

    数据库(xxx) --->安全性---->架构---->dbo(属性)--->权限--->添加--->浏览-->public 添加 select 等您需要的权 ...

  10. 抓老鼠 codeForce 148D - Bag of mice 概率DP

    设dp[i][j]为有白老鼠i只,黑老鼠j只时轮到公主取时,公主赢的概率. 那么当i = 0 时,为0 当j = 0时,为1 公主可直接取出白老鼠一只赢的概率为i/(i+j) 公主取出了黑老鼠,龙必然 ...