如何用ASP.NET MVC生成Code 39、Code 128或ISBN一维条码?

2026-03-30 13:301阅读0评论SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计652个文字,预计阅读时间需要3分钟。

如何用ASP.NET MVC生成Code 39、Code 128或ISBN一维条码?

[ASP.NET MVC] 生成一维条形码(Code 39、Code 128、ISBN)- 最新项目急需生产Code39一维条形码,已找到此Library:BarcodeLib,支持多种格式(Code 128、Code 11、Code 39等),更多信息请访问:[链接]

[ASP.NET MVC]Barcode 产生一维条码(Code 39、Code128、ISBN)


最近项目刚好要产生Code39一维条码,找到了这个Library

BarcodeLib

支持多种(Code 128、Code 11、Code 39..等等)

(图节录自www.codeproject.com/Articles/20823/Barcode-Image-Generation-Library)

如何用ASP.NET MVC生成Code 39、Code 128或ISBN一维条码?

说明:

1.先下载BarcodeLib

2.把BarcodeLib.dll加入参考至项目

?

3.建立Barcode方法在Controller

1: using System;

2: using System.Collections.Generic;

3: using System.Linq;

4: using System.Web;

5: using System.Web.Mvc;

6: using BarcodeLib;

7: using System.Drawing;

8: using System.Drawing.Imaging;

9: namespace BarcodeDemo.Controllers

10: {

11: public class HomeController : Controller

12: {

13: // GET: Home

14: public ActionResult Index()

15: {

16: return View();

17: }

18:?

19: public void Barcode(string sn = null)

20: {

21: Response.ContentType = "image/gif";

22: Barcode bc = new Barcode();

23: bc.IncludeLabel = true;//显示文字标签

24: bc.LabelFont = new Font("Verdana", 9f);//文字标签字型、大小

25: bc.Width = 300;//宽度

26: bc.Height = 100;//高度

27: Image img = bc.Encode(TYPE.CODE39, sn, bc.Width, bc.Height);//产生影像

28: img.Save(Response.OutputStream, ImageFormat.Gif);

29: Response.End();

30: }

31: }

32: }

PS:如需修改条码类型,则修改{TYPE.CODE39}部分

4.这时候我们已经可以用网址取得图片了

但如果想在网页中加入

在网页中加入此行,SN部分则为条码内容

1:

PS:笔者在编码内容为写死,通常会从数据库中抓取该商品的编码内容

另外可以依照需求把图片产生后存在server端,才不用每次读取时再算一次图。

附上此范例项目档(GitHub):github.com/mrsunboss/BarcodeDemo_WEB


如有错误还请各位先进前辈们不吝啬的指教,谢谢。

?

原文:大专栏 [ASP.NET MVC] 产生一维条码Barcode(Code 39、Code128、ISBN)

本文共计652个文字,预计阅读时间需要3分钟。

如何用ASP.NET MVC生成Code 39、Code 128或ISBN一维条码?

[ASP.NET MVC] 生成一维条形码(Code 39、Code 128、ISBN)- 最新项目急需生产Code39一维条形码,已找到此Library:BarcodeLib,支持多种格式(Code 128、Code 11、Code 39等),更多信息请访问:[链接]

[ASP.NET MVC]Barcode 产生一维条码(Code 39、Code128、ISBN)


最近项目刚好要产生Code39一维条码,找到了这个Library

BarcodeLib

支持多种(Code 128、Code 11、Code 39..等等)

(图节录自www.codeproject.com/Articles/20823/Barcode-Image-Generation-Library)

如何用ASP.NET MVC生成Code 39、Code 128或ISBN一维条码?

说明:

1.先下载BarcodeLib

2.把BarcodeLib.dll加入参考至项目

?

3.建立Barcode方法在Controller

1: using System;

2: using System.Collections.Generic;

3: using System.Linq;

4: using System.Web;

5: using System.Web.Mvc;

6: using BarcodeLib;

7: using System.Drawing;

8: using System.Drawing.Imaging;

9: namespace BarcodeDemo.Controllers

10: {

11: public class HomeController : Controller

12: {

13: // GET: Home

14: public ActionResult Index()

15: {

16: return View();

17: }

18:?

19: public void Barcode(string sn = null)

20: {

21: Response.ContentType = "image/gif";

22: Barcode bc = new Barcode();

23: bc.IncludeLabel = true;//显示文字标签

24: bc.LabelFont = new Font("Verdana", 9f);//文字标签字型、大小

25: bc.Width = 300;//宽度

26: bc.Height = 100;//高度

27: Image img = bc.Encode(TYPE.CODE39, sn, bc.Width, bc.Height);//产生影像

28: img.Save(Response.OutputStream, ImageFormat.Gif);

29: Response.End();

30: }

31: }

32: }

PS:如需修改条码类型,则修改{TYPE.CODE39}部分

4.这时候我们已经可以用网址取得图片了

但如果想在网页中加入

在网页中加入此行,SN部分则为条码内容

1:

PS:笔者在编码内容为写死,通常会从数据库中抓取该商品的编码内容

另外可以依照需求把图片产生后存在server端,才不用每次读取时再算一次图。

附上此范例项目档(GitHub):github.com/mrsunboss/BarcodeDemo_WEB


如有错误还请各位先进前辈们不吝啬的指教,谢谢。

?

原文:大专栏 [ASP.NET MVC] 产生一维条码Barcode(Code 39、Code128、ISBN)