建議不要用CODE-39碼,改用CODE-128碼;
CODE-39碼密度比較低,條碼數(shù)字內(nèi)容太多,導(dǎo)致條碼太長,縮短長度就只能減小X尺寸,造成識讀困難;
CODE-128碼密度高,相同的數(shù)字生成條碼更短。
你可以對比一下圖中的兩個條碼,上面是CODE-39,下面是CODE-128,相同的內(nèi)容:
解決方案:
Default.aspx
%201%20<%@%20Page%20Language="C#"%20AutoEventWireup="true"%20CodeBehind="Default.aspx.cs"%20Inherits="BarcodeTest.Default"%20%>%202%20%203%20<!DOCTYPE%20html>%204%20%205%20<html%20xmlns="http://www.w3.org/1999/xhtml">%206%20<head%20runat="server">%207%20%20%20%20%20<meta%20http-equiv="Content-Type"%20content="text/html;%20charset=utf-8"%20/>%208%20%20%20%20%20<title>條形碼</title>%209%20%20%20%20%20<scrCharacterSet.cs
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 6 //author: Kenmu 7 //created by: 2014-11-05 8 //function: 條形碼 9 namespace Barcode10 {11 /// <summary> 12 /// Code128字符集 13 /// </summary> 14 internal enum CharacterSet15 {16 A,17 B,18 C19 } 20 }IBarCode.cs
1 using System; 2 using System.Collections.Generic; 3 using System.Drawing; 4 using System.Linq; 5 using System.Text; 6 7 //author: Kenmu 8 //created by: 2014-11-05 9 //function: 條形碼10 namespace Barcode11 {12 /// <summary> 13 /// 條形碼接口 14 /// </summary> 15 public interface IBarCode16 {17 string RawData { get; }18 /// <summary> 19 /// 條形碼對應(yīng)的數(shù)據(jù) 20 /// </summary> 21 string EncodedData { get; }22 /// <summary> 23 /// 當(dāng)前條形碼標(biāo)準(zhǔn) 24 /// </summary> 25 string BarCodeType { get; }26 27 /// <summary> 28 /// 得到條形碼對應(yīng)的圖片 29 /// </summary> 30 /// <returns></returns> 31 Image GetBarCodeImage();32 }33 }BaseCode128.cs
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Drawing; 6 7 //author: Kenmu 8 //created by: 2014-11-06 9 //function: 條形碼 10 namespace Barcode 11 { 12 /// <summary> 13 /// BaseCode128抽象類 14 /// </summary> 15 public abstract class BaseCode128 : IBarCode 16 { 17 protected Color backColor = Color.White;//條碼背景色 18 protected Color barColor = Color.Black;//條碼和原始數(shù)據(jù)字體顏色 19 20 /// <summary> 21 /// 當(dāng)前條形碼種類 22 /// </summary> 23 public string BarCodeType 24 { 25 get { return System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name; } 26 } 27 28 /// <summary> 29 /// 條形碼對應(yīng)的編碼數(shù)據(jù) 30 /// </summary> 31 protected string _EncodedData; 32 public string EncodedData 33 { 34 get { return this._EncodedData; } 35 } 36 37 /// <summary> 38 /// 【原始數(shù)據(jù)】 39 /// </summary> 40 protected string _RawData; 41 public string RawData 42 { 43 get { return this._RawData; } 44 } 45 46 /// <summary> 47 /// 在條形碼下面顯示數(shù)據(jù);如果為空,則取【原始數(shù)據(jù)】 48 /// </summary> 49 protected string _PresentationData = null; 50 public string PresentationData 51 { 52 get { return string.IsNullOrEmpty(this._PresentationData) ? this._RawData : this._Present
新聞熱點
疑難解答