• C#条形码


    条形码的三种维码却别:
    ①一维条形码:
    一维条形码只是在一个方向(一般是水平方向)表达信息,而在垂直方向则不表达任何信息,其一定的高度通常是为了便于阅读器的对准。
    一维条形码的应用可以提高信息录入的速度,减少差错率,但是一维条形码也存在一些不足之处:
    * 数据容量较小:30个字符左右
    * 只能包含字母和数字
    * 条形码尺寸相对较大(空间利用率较低)
    * 条形码遭到损坏后便不能阅读

    ②二维条形码:
    在水平和垂直方向的二维空间存储信息的条形码, 称为二维条形码(2-dimensional bar code)。
    与一维条形码一样,二维条形码也有许多不同的编码方法,或称码制。就这些码制的编码原理而言,通常可分为以下三种类型
    ⒈ 线性堆叠式二维码
    是在一维条形码编码原理的基础上,将多个一维码在纵向堆叠而产生的。典型的码制如:Code 16K、Code 49.PDF417等。
    2. 矩阵式二维码
    是在一个矩形空间通过黑、白像素在矩阵中的不同分布进行编码。典型的码制如:Aztec、Maxi Code、QR Code、 Data Matrix等。
    3. 邮政码
    通过不同长度的条进行编码,主要用于邮件编码,如:Postnet、BPO 4-State。
    在许多种类的二维条形码中,常用的码制有:Data Matrix,Maxi Code,Aztec,QR Code,Vericode,PDF417,Ultracode,Code 49,Code 16K 等,其中:
    * Data Matrix 主要用于电子行业小零件的标识,如英特尔(Intel)的奔腾处理器的背面就印制了这种码。
    * Maxi Code 是由美国联合包裹服务(UPS)公司研制的,用于包裹的分拣和跟踪。
    * Aztec 是由美国韦林(Welch Allyn)公司推出的,最多可容纳3832个数字或3067个字母字符或1914个字节的数据。

    Generatel1为生成一维码的方法

    Generatel2为生成二维码的方法

    dll文件下载地址:https://files.cnblogs.com/files/lbjlbj/zxing.7z

    控制器中:

    public class ShowController : Controller
        {
            // GET: Show
            public ActionResult Index()
            {
                return View();
            }
            public  string Generate1(string text)
            {
                int width = 60; int height = 60;
                Random rd = new Random(10);
                string time = DateTime.Now.ToString("yyyyMMdd")+"erwei";
                string path = Server.MapPath("~/Images" + "//" + time + ".Png");
                string path1 = $"http://localhost:53183/Images/{time}" + ".Png";
                BarcodeWriter writer = new BarcodeWriter();
                writer.Format = BarcodeFormat.QR_CODE;
                QrCodeEncodingOptions options = new QrCodeEncodingOptions()
                {
                    DisableECI = true,
    
                     //设置内容编码
                    CharacterSet = "UTF-8", 
                    //设置二维码的宽度和高度
                    Width = width,
                    Height = height,
                    Margin = 1//设置二维码的边距,单位不是固定像素
                };
    
                writer.Options = options;
                Bitmap map = writer.Write(text);
                map.Save(path, ImageFormat.Png);
                return path1;
            }
            public string Generate2(string text)
            {
                int width = 80; int height = 60;
                Random rd = new Random(10);
                string time = DateTime.Now.ToString("yyyyMMdd")+rd.Next().ToString();
                string path = Server.MapPath("~/Images" + "//" + time + ".Png");
                string path1 = $"http://localhost:53183/Images/{time}" + ".Png";
                BarcodeWriter writer = new BarcodeWriter();
                //使用ITF 格式,不能被现在常用的支付宝、微信扫出来
                //如果想生成可识别的可以使用 CODE_128 格式
                //writer.Format = BarcodeFormat.ITF;
                writer.Format = BarcodeFormat.CODE_39;
                EncodingOptions options = new EncodingOptions()
                {
                    Width = width,
                    Height = height,
                    Margin = 2
                };
                writer.Options = options;
                Bitmap map = writer.Write(text);
                map.Save(path, ImageFormat.Png);
                return path1;
            }
    
        }

    视图中:

    <div> 
            <input id="txt" type="text" />
            <input id="Button1" type="button" value="生成条形码图片" onclick="tiao()"/>
            <input id="Button1" type="button" value="生成二维码图片" onclick="Er()"/>
            <img src="" alt="" id="tx"/>
            <img src="" alt="" id="erwei"/>
        </div>

    Ajax:

    <script>
        function Er() {
            $.ajax({
                url: "/Show/Generate1",
                data: { text: $("#txt").val() },
                dataType: "text",
                success: function (data) {
                    $("#erwei").attr("src",data);
                }
            })
        }
        function tiao() {
            $.ajax({
                url: "/Show/Generate2",
                data: { text: $("#txt").val() },
                dataType: "text",
                success: function (data) {
                    $("#tx").attr("src", data);
                }
            })
        }
    </script>

    ③彩色条形码
    彩色条码主要是结合带有视像镜头的手提电话或个人电脑,利用镜头来阅读杂志、报纸、电视机或电脑屏幕上的颜色条码,并传送到数据中心。数据中心会因应收到的颜色条码来提供网站资料或消费优惠。
    彩色条码比二维条码优胜的地方,是它可以利用较低的分辨率来提供较高的数据容量。一方面,颜色条码无需要较高分辨率的镜头来解读,使沟通从单向变成双方面,二来较低的分辨率亦令使用条码的公司在条码上加上变化,以提高读者参与的兴趣。
    新的彩色条码将使用4或8种颜色,在较少的空间中储存更多的资讯,并以小三角形取代传统的长方形。由CNET新闻中公布的图片看来,类似彩色版的二维QR条码。彩色条码未来计划用于电影、电玩等商业性媒介上,以冀提供更高的安全性,甚至电影宣传片连结或其他附加功能。

  • 相关阅读:
    jedis异常:Could not get a resource from the pool
    redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resourc
    【redis】常见JedisConnectionException异常分析
    JAVA,字符串首字母转大写(高效率)
    Type handler was null on parameter mapping for property 'products'. It was either not specified and/or could not be found for the javaType / jdbcType combination specified
    java读取blob,clob转换为字符串
    mybatis对blob属性数据的处理
    mybatis读取oracle中blob
    jpa2.x的getOne()/findOne()/findById()的区别及使用
    IDEA如何导入导出出settings配置文件
  • 原文地址:https://www.cnblogs.com/lbjlbj/p/10564525.html
Copyright © 2020-2023  润新知