Interface, such an interface can be applied to a variety of one-dimensional, two-dimensional code
/// <Summary> /// bar code interface /// </summary> public interface IBarCode {string RawData {get ;} /// <summary> /// data corresponding to the barcode /// </summary> string EncodedData {get ;} /// <summary> /// current bar code standard /// </summary> string BarCodeType {get ;} /// <summary> /// obtain the Image corresponding to the barcode /// </summary> /// <returns> </returns> Image GetBarCodeImage ();}
Code128 static class, storing some basic Code128 information and sharing methods
/// <Summary> /// Code128 basic related classes /// </summary> internal static class Code128 {/** 128 dimension requirement * Minimum module width x maximum 1.016mm, minimum 0.250mm x in a system should be a constant value of 1mm, and the amplification factor is 0.25 ~ The minimum width of the blank area on the left and right is 1.2 X. The maximum physical length cannot exceed 165mm, and the maximum number of encoded data characters is 48, it includes the application identifier and the FNC1 character used as the separator, but does not include the auxiliary character and the checkpoint character ** the FNC1 in AI also uses ** ASCII ** 0 ~ as the Separator ~ 31 StartA private * 96 ~ 127 StartB private ** EAN128 does not use spaces (ASCII code 32) * /// <summary> // Code128 empty sorting set, 1 indicates B, 0 indicates null s, and the Index corresponds to the symbol character value S // </summary> internal static readonly List <string> BSList = new List <string> () {"212222 ", "222122", "222221", "121223", "121322", "131222", "122213", "122312", "132212", "221213", "221312 ", "231212", "112232", "122132", "122231", "113222", "123122", "123221", "223211", "221132", "221231", "213212", "223112", "312131", "311222", "321122", "321221", "312212", "322112 ", "322211", "212123", "212321", "232121", "111323", "131123", "131321", "112313", "132113", "132311 ", "211313", "231113", "231311", "112133", "112331", "132131", "113123", "113321", "133121", "313121 ", "211331", "231131", "213113", "213311", "213131", "311123", "311321 "," 331121 "," 312113 "," 312311 "," 332111 "," 314111 "," 221411 "," 431111 "," 111224 "," 111422 "," 121124 ", "121421", "141122", "141221", "112214", "112412", "122114", "122411", "142112", "142211", "241211 ", "221114", "413111", "241112", "134111", "111242", "121142", "121241", "114212", "124112", "124211 ", "411212", "421112", "421211", "212141", "214121", "412121", "1111" 43 "," 111341 "," 131141 "," 114113 "," 114311 "," 411113 "," 411311 "," 113141 "," 114131 "," 311141 ", "411131", "211412", "211214", "211232", "2331112" };# empty array set of region entries // {// "11011001100", "11001101100 ", "11001100110", "10010011000", "10010001100", // "10001001100", "10011001000", "10011000100", "10001100100", "11001001000", // "11001000100 ", "11000100100", "10110011100", "1 0011011100 "," 10011001110 ", //" 10111001100 "," 10011101100 "," 10011100110 "," 11001110010 "," 11001011100 ", //" 11001001110 "," 11011100100 ", "11001110100", "11101101110", "11101001100", // "11100101100", "11100100110", "11101100100", "11100110100", "11100110010", // "11011011000 ", "11011000110", "11000110110", "10100011000", "10001011000", // "10001000110", "10110001000", "10 001101000 "," 10001100010 "," 11010001000 ", //" 11000101000 "," 11000100010 "," 10110111000 "," 10110001110 "," 10001101110 ", //" 10111011000 ", "10111000110", "10001110110", "11101110110", "11010001110", // "11000101110", "11011101000", "11011100010", "11011101110", "11101011000 ", // "11101000110", "11100010110", "11101101000", "11101100010", "11100011010", // "11101111010", "110" 01000010 "," 11110001010 "," 10100110000 "," 10100001100 ", //" 10010110000 "," 10010000110 "," 10000101100 "," 10000100110 "," 10110010000 ", // "10110000100", "10011010000", "10011000010", "10000110100", "10000110010", // "11000010010", "11001010000", "11110111010", "11000010100 ", "10001111010", // "10100111100", "10010111100", "10010011110", "10111100100", "10011110100", // "1001 1110010 "," 11110100100 "," 11110010100 "," 11110010010 "," 11011011110 ", //" 11011110110 "," 11110110110 "," 10101111000 "," 10100011110 ", "10001011110", // "10111101000", "10111100010", "11110101000", "11110100010", "10111011110", // "10111101110", "11101011110", "11110101110 ", "11010000100", "11010010000", // "11010011100", "1100011101011" //}; # endregion internal const byte FNC3 _ AB = 96, FNC2_ AB = 97, SHIFT_ AB = 98, CODEC_ AB = 99, CODEB_AC = 100, CODEA_BC = 101; internal const byte FNC4_A = 101, FNC4_ B = 100; internal const byte FNC1 = 102, StartA = 103, StartB = 104, StartC = 105; internal const byte Stop = 106; /// <summary> /// obtain the character value S corresponding to Character Set A /// </summary> /// <param name = "c"> </param> // <returns> </returns> internal static byte GetSIndexFromA (char c) {byte sInd Ex = (byte) c; // Character Set A. If ASCII is <32, S = ASCII + 64, if 95> = ASCII> = 32, then S = ASCII-32 if (sIndex <32) {sIndex + = 64;} else if (sIndex <96) {sIndex-= 32;} else {throw new NotImplementedException ();} return sIndex ;} /// <summary> /// obtain the character S in Character Set B. /// </summary> /// <param name = "c"> </param> // <returns> </returns> internal static byte GetSIndexFromB (char c) {byte sIndex = (byte) c; if (sIn Dex> 31 & sIndex <128) {sIndex-= 32; // the ASCII code in Character Set B is equal to the symbolic character value after 32 is subtracted.} else {throw new NotImplementedException ();} return sIndex;} internal static byte GetSIndex (CharacterSet characterSet, char c) {switch (characterSet) {case CharacterSet. a: return GetSIndexFromA (c); case CharacterSet. b: return GetSIndexFromB (c); default: throw new NotImplementedException () ;}/// <summary> /// determine whether the specified character only belongs Character Set // </summary> /// <param name = "characterSet"> </param> /// <param name = "c"> </param>/ // <returns> </returns> internal static bool charonlybelonsto (CharacterSet characterSet, char c) {switch (characterSet) {case CharacterSet. a: return (byte) c <32; case CharacterSet. b: return (byte) c> 95 & (byte) c <128; default: throw new NotImplementedException ();}} /// <summary> /// determines whether the specified character is not in the specified character set/ /// </Summary> /// <param name = "characterSet"> </param> /// <param name = "c"> </param> // <returns> </returns> internal static bool charnotbelonsto (CharacterSet characterSet, char c) {switch (characterSet) {case CharacterSet. a: return (byte) c> 95; case CharacterSet. b: return (byte) c <32 & (byte) c> 127; default: throw new NotImplementedException ();}} /// <summary> /// obtain the symbol character value corresponding to the switch character during encoding conversion/ /// </Summary> /// <param name = "newCharacterSet"> </param> /// <returns> </returns> internal static byte GetCodeXIndex (CharacterSet newCharacterSet) {switch (newCharacterSet) {case CharacterSet. a: return CODEA_BC; case CharacterSet. b: return CODEB_AC; default: return CODEC_ AB ;}} /// <summary> /// obtain the converted character set /// </summary> /// <param name = "characterSet"> </param> // <returns> </returns> internal sta Tic CharacterSet GetShiftCharacterSet (CharacterSet characterSet) {switch (characterSet) {case CharacterSet. a: return CharacterSet. b; case CharacterSet. b: return CharacterSet. a; default: throw new NotImplementedException ();}} /// <summary> /// obtain the expected Character Set // </summary> /// <param name = "data"> </param> // <param name = "startIndex"> Start position </param> // <returns> </returns> internal static CharacterSet GetCharacterSet (string data, int startIndex) {CharacterSet returnSet = CharacterSet. b; if (Regex. isMatch (data. substring (startIndex), @ "^ \ d {4,}") {returnSet = CharacterSet. c;} else {byte byteC = GetProprietaryChar (data, startIndex); returnSet = byteC <32? CharacterSet. a: CharacterSet. b;} return returnSet;} // <summary> // starting from the specified position, return the first one greater than 95 (and less than 128) or a value less than 32 characters /// </summary> /// <param name = "data"> </param> /// <param name = "startIndex"> </param> /// <returns> if no character matches, returns 255 </returns> internal static byte GetProprietaryChar (string data, int startIndex) {byte returnByte = byte. maxValue; for (int I = startIndex; I <data. length; I ++) {byte C = (byte) data [I]; if (byteC <32 | byteC> 95 & byteC <128) {returnByte = byteC; break ;}} return returnByte ;} /// <summary> /// obtain the number of consecutive numbers that appear from the specified position. // </summary> /// <param name = "data"> </ param> /// <param name = "startIndex"> </param> /// <returns> </returns> internal static int GetDigitLength (string data, int startIndex) {int digitLength = data. length-startIndex; // The default value starts from the starting position and ends with a number. (Int I = startIndex; I <data. Length; I ++) {if (! Char. IsDigit (data [I]) {digitLength = I-startIndex; break ;}return digitLength ;}}
Code128 Character Set enumeration class
/// <Summary> /// Code128 Character Set /// </summary> internal enum CharacterSet {A, B, C}