条形码与二维码的区别(windowsForm)

一:概念
二维码: 又称二维条码,是在一维条码的基础上扩展出的一种具有可读性的条码。设备扫描二维条码,通过识别条码的长度和宽度中所记载的二进制数据,可获取其中所包含的信息.
条形码: 将宽度不等的多个黑条和空白,按照一定的编码规则排列,用以表达一组信息的图形标识符;
二:. 条形码优缺点:
条形码技术具有以下几个方面的优点:
(1)输入速度快:与键盘输入相比,条形码输入的速度是键盘输入的5倍,并且能实现“即时数据输入”。
(2)可靠性高: 键盘输入数据出错率为三百分之一,利用光学字符识别技术出错率为万分之一,而采用条形码技术误码率低于百万分之一。
(3) 采集信息量大:利用传统的一维条形码一次可采集几十位字符的信息,二维条形码更可以携带数千个字符的信息,并有一定的自动纠错能力。
(4)灵活实用:条形码标识既可以作为一种识别手段单独使用,也可以和有关识别设备组成一个系统实现自动化识别,还可以和其他控制设备联接起来实现自动化管理。
(5)另外,条形码标签易于制作,对设备和材料没有特殊要求, 识别设备操作容易,不需要特殊培训,且设备也相对便宜。成本非常低。在零售业领域,因为条码是印刷在商品包装上的,所以其成本几乎为“零’
条形码技术具有以下几个方面的缺点:
(1):数据容量较小: 30个字符左右;
(2) 只能包含字母和数字;
(3)条形码尺寸相对较大(空间利用率较低);
(4) 条形码遭到损坏后便不能阅读;
二维码技术具有以下几个方面的优点:
(1) 数据容量更大;
(2)超越了字母数字的限制;
(3)条形码相对尺寸小;
(4)具有抗损毁能力;
(5)成本低,易制作,持久耐用;
二维码技术具有以下几个方面的优点:
(1)可以利用二维码下载病毒软件;
三: 应用场景
二维码: 食品追溯方案 ,餐厅的应用 ,手机购物 ,扫钱扫优惠 ,二维码放置 , 二维码DM, 二维码印章▪, 婚礼应用等;
条形码: 商品流通、图书管理、邮政管理、银行系统等;

四:使用案例
条形码
界面:
在这里插入图片描述
结果:
在这里插入图片描述
需要用到的程序包:
在这里插入图片描述
代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 条形码
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//条形码
private void button1_Click(object sender, EventArgs e)
{
System.Drawing.Image image;
//设定宽度与高度
int width = 200, height = 160;
string fileSavePath = AppDomain.CurrentDomain.BaseDirectory + “BarcodePattern1.jpg”;
if (File.Exists(fileSavePath))
File.Delete(fileSavePath);
GetBarcode(height, width, BarcodeLib.TYPE.CODE128, “20190320-136”, out image, fileSavePath);

        pictureBox1.Image = Image.FromFile("BarcodePattern1.jpg");
    }
    public static void GetBarcode(int height, int width, BarcodeLib.TYPE type, string code, out System.Drawing.Image image, string fileSaveUrl)
    {
        try
        {
            image = null;
            BarcodeLib.Barcode b = new BarcodeLib.Barcode();
            b.BackColor = System.Drawing.Color.White;//图片背景颜色
            b.ForeColor = System.Drawing.Color.Black;//条码颜色
            b.IncludeLabel = true;
            b.Alignment = BarcodeLib.AlignmentPositions.LEFT;
            b.LabelPosition = BarcodeLib.LabelPositions.BOTTOMCENTER;
            b.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;//图片格式
            System.Drawing.Font font = new System.Drawing.Font("verdana", 10f);//字体设置
            b.LabelFont = font;
            b.Height = height;//图片高度设置(px单位)
            b.Width = width;//图片宽度设置(px单位)

            image = b.Encode(type, code);//生成图片
            image.Save(fileSaveUrl, System.Drawing.Imaging.ImageFormat.Jpeg);

        }
        catch (Exception ex)
        {

            image = null;
        }
    }

    private void button2_Click(object sender, EventArgs e)
    {
        System.Drawing.Image image;
        int width = 200, height = 160;
        string fileSavePath = AppDomain.CurrentDomain.BaseDirectory + "BarcodePattern.jpg";
        //if (File.Exists(fileSavePath))
        //    File.Delete(fileSavePath);
        GetBarcode1(height, width, BarcodeLib.TYPE.CODE128, "20190215-136", out image, fileSavePath);

        pictureBox2.Image = Image.FromFile("BarcodePattern.jpg");
    }
    public static void GetBarcode1(int height, int width, BarcodeLib.TYPE type, string code, out System.Drawing.Image image, string fileSaveUrl)
    {
        try
        {
            image = null;
            BarcodeLib.Barcode b = new BarcodeLib.Barcode();
            b.BackColor = System.Drawing.Color.White;//图片背景颜色
            b.ForeColor = System.Drawing.Color.Black;//条码颜色
            b.IncludeLabel = true;
            b.Alignment = BarcodeLib.AlignmentPositions.LEFT;
            b.LabelPosition = BarcodeLib.LabelPositions.BOTTOMCENTER;
            b.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;//图片格式
            System.Drawing.Font font = new System.Drawing.Font("verdana", 8f);//字体设置
            b.LabelFont = font;
            b.Height = height;//图片高度设置(px单位)
            b.Width = width;//图片宽度设置(px单位)

            image = b.Encode(type, code);//生成图片
            image.Save(fileSaveUrl, System.Drawing.Imaging.ImageFormat.Jpeg);

        }
        catch (Exception ex)
        {

            image = null;
        }
    }
}

}
二维码
界面:
在这里插入图片描述
结果:
在这里插入图片描述
需要用到的程序包:
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190320165400371.PNG在这里插入图片描述
代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using ZXing;
using ZXing.QrCode;

namespace 二维码
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

    private void Form1_Load(object sender, EventArgs e)
    {

    }
    private void button2_Click(object sender, EventArgs e)
    {
        BarcodeWriter writer = new BarcodeWriter();
        writer.Format = BarcodeFormat.QR_CODE;
        QrCodeEncodingOptions options = new QrCodeEncodingOptions()
        {
            DisableECI = true,
            CharacterSet = "UTF-8",
            Width = pictureBox1.Width,
            Height = pictureBox1.Height,
            Margin = 1
        };

        writer.Options = options;
        Bitmap map = writer.Write("生成二维码测试生成二维码测试生成二维码测试生成二" +
            "维码测试生成二维码测试生成二维码测试生成二维码测试生成二维码测试生成二维" +
            "码测试生成二维码测试生成二维码测试生成二维码测试生成二维码测试生成二维码测试生成二维码测试");
        pictureBox1.Image = map;
    }
}

}
希望可以帮助到你O(∩_∩)O~
参考详细网址:https://blog.csdn.net/arrowzz/article/details/80862759

猜你喜欢

转载自blog.csdn.net/ProteaCynaroides/article/details/88693388