zoukankan      html  css  js  c++  java
  • asp.net用Zxing库实现条形码输出

      这个简单的问题,困扰了我将近两个小时,主要是再官方文档上没有找到demo,那只能用搜索引擎了,看看其他程序员写的程序,但是发现处处是坑,看了四五个例子,没有一个可以正常运行的,全部报错,经过一个多小时的尝试,才最终搞定。不多说了,直接上截图和代码。

      首先要在项目中添加zxing.dll引用(zxing.dll下载地址http://zxingnet.codeplex.com/)

      

    其次就是建立aspx文件,在后台中代码如下

    using ZXing.Common;
    using ZXing;
    using ZXing.Rendering;
    using System.Drawing;
    using System.Drawing.Imaging;
    using ZXing.QrCode.Internal;
    
    namespace zxingtm
    {
        public partial class txm : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                MultiFormatWriter mutiWriter = new MultiFormatWriter();
                BitMatrix bm = mutiWriter.encode("123456789", BarcodeFormat.CODE_39, 363, 150);
                Bitmap img = new BarcodeWriter().Write(bm);
                img.Save("d:/1.jpeg", System.Drawing.Imaging.ImageFormat.Jpeg);
            }
        }
    }
    

    代码中“123456789”在测试中我是写死的,用的时候可以用变量代替。BarcodeFormat.CODE_39等参数可以换成其他的,用以生成其他格式的条形码

    这样的话在d盘就输出了1.jepg的条形码图片,这里主要功能已经实现,生成的条形码图片如下:

    用手机自带的扫描条形码功能扫了下,结果正是123456789

  • 相关阅读:
    EntityFramework 启用迁移 EnableMigrations 报异常 "No context type was found in the assembly"
    JAVA 访问FTP服务器示例(2)
    NuGet Package Manager 更新错误解决办法
    JAVA 访问FTP服务器示例(1)
    RemoteAttribute 的使用问题
    诡异的 javascript 变量
    javascript apply用法
    Babun 中文乱码
    GSM呼叫过程
    转站博客园
  • 原文地址:https://www.cnblogs.com/wjcnet/p/3491148.html
Copyright © 2011-2022 走看看