asp.net用Zxing庫實現條碼輸出的具體實現_實用技巧

來源:互聯網
上載者:User

這個簡單的問題,困擾了我將近兩個小時,主要是再官方文檔上沒有找到demo,那隻能用搜尋引擎了,看看其他程式員寫的程式,但是發現處處是坑,看了四五個例子,沒有一個可以正常啟動並執行,全部報錯,經過一個多小時的嘗試,才最終搞定。不多說了,直接上截圖和代碼。

首先要在項目中添加zxing.dll引用(zxing.dll下載地址http://www.jb51.net/dll/zxing.dll.html)

 

其次就是建立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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.