下载地址: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. 火狐浏览器访问网站出现 HTTP Error 400. The request is badly formed.错误,怎么解决

    今天在访问某个网站时,出现一个“HTTP Error 400. The request is badly formed.”错误, 那么应该如何解决呢? 1.问题描述: 用火狐浏览网站出现“”HTTP ...

  2. 吐血推荐:罗马尼亚无版权VPS服务商HostSolutions评测-绝对真实

    要放心大胆的玩 VPS,要找性价比高.信用好,服务稳定,限制少的服务商是很不容易的.这里我先点几个黑名单:第一类 HiFormance.VirMach 低价流 VPS 服务商,以低从吸引消费者.俗话说 ...

  3. Android系统移植与驱动开发

    21世纪,Android发展非常迅速,在市场上占有很大的比例,遥遥领先与iOS,很大程度上是因为任何人都可以利用Android的源代码定制完全属于自己的嵌入式开发系统,而不需要向Google交一分钱. ...

  4. iPad mini Retina越狱小结【2014年02月06日 - 初稿】

    Update History 2014年02月06日 - 初稿 0.引言 本来一直都没有苹果的产品除了第一代的iPod(没怎么使用最后大学送人了 @李清纯(255270520) ,巧合的是老妈学校发了 ...

  5. QQ提示应用程序并行配置不正确,绿色版QQ不能运行解决方法

    出现此问题是因为您的计算机中缺少VC运行库导致的,建议您到互联网上下载相应的VC2005运行库,Windows 7请下载VC2008运行库安装到您的计算机中.如果您安装了运行库还是不行,建议您安装:( ...

  6. mysql数据库索引相关

    一 介绍 什么是索引? 索引在MySQL中也叫做“键”,是存储引擎用于快速找到记录的一种数据结构.索引对于良好的性能非常关键,尤其是当表中的数据量越来越大时,索引对于性能的影响愈发重要.索引优化应该是 ...

  7. iOS 开发 Framework

    制作Framework 的好处和缺点 好处:       1.如果模块间接口定义的比较完善,模块化的程序具有很好的可扩展性与内聚性:       2.物理上的模块化便于开发过程的管理与测试,尤其是在程 ...

  8. docker-compose工具

    环境:CentOS7.0 安装版本:1.3.2 参考资料:https://docs.docker.com/compose/install/ 安装方式: [root@Docker ~]#curl -L ...

  9. makefile for opencv

    makefile #################################################### # Generic makefile - 万能Makefile # for ...

  10. Word Embeddings

    能够充分意识到W的这些属性不过是副产品而已是很重要的.我们没有尝试着让相似的词离得近.我们没想把类比编码进不同的向量里.我们想做的不过是一个简单的任务,比如预测一个句子是不是成立的.这些属性大概也就是 ...