條形碼生成

2022-02-24 05:14:03 字數 4143 閱讀 4837

生成條形碼的類

public class barcode128dll

set }

private font m_valuefont = new font("宋體",10);

///

/// 是否顯示可見號碼  如果為null不顯示號碼

///

public font valuefont set }

private byte m_magnify = 0;

///

/// 放大倍數

///

public byte magnify set }

///

/// 條碼類別

///

public enum encode

public code128()

", "93", "111341");

m_code128.rows.add("94", "rs", "~", "94", "131141");

m_code128.rows.add("95", "us", "del", "95", "114113");

m_code128.rows.add("96", "fnc3", "fnc3", "96", "114311");

m_code128.rows.add("97", "fnc2", "fnc2", "97", "411113");

m_code128.rows.add("98", "shift", "shift", "98", "411311");

m_code128.rows.add("99", "codec", "codec", "99", "113141");

m_code128.rows.add("100", "codeb", "fnc4", "codeb", "114131");

m_code128.rows.add("101", "fnc4", "codea", "codea", "311141");

m_code128.rows.add("102", "fnc1", "fnc1", "fnc1", "411131");

m_code128.rows.add("103", "starta", "starta", "starta", "211412");

m_code128.rows.add("104", "startb", "startb", "startb", "211214");

m_code128.rows.add("105", "startc", "startc", "startc", "211232");

m_code128.rows.add("106", "stop", "stop", "stop", "2331112");

#endregion

} ///

/// 獲取128圖形

///

/// 文字

/// 編碼

/// 圖形

public bitmap getcodeimage(string p_text, encode p_code)

catch

_text += getvalue(p_code, p_text.substring(0, 2), ref _temp);

_textnumb.add(_temp);

p_text = p_text.remove(0, 2);

} break;

case encode.ean128:

_examine = 105;

if (!((p_text.length & 1) == 0)) throw new exception("ean128長度必須是偶數");

_textnumb.add(102);

_text += "411131";

while (p_text.length != 0)

catch

_text += getvalue(encode.code128c, p_text.substring(0, 2), ref _temp);

_textnumb.add(_temp);

p_text = p_text.remove(0, 2);

} break;

default:

if (p_code == encode.code128a)

else

while (p_text.length != 0)

break;

} if (_textnumb.count == 0) throw new exception("錯誤的編碼,無資料");

_text = _text.insert(0, getvalue(_examine)); //獲取開始位

for (int i = 0; i != _textnumb.count; i++)

_examine = _examine % 103;           //獲得嚴效位

_text += getvalue(_examine);  //獲取嚴效位

_text += "2331112"; //結束位

bitmap _codeimage = getimage(_text);

getviewtext(_codeimage, _viewtext);

return _codeimage;

} ///

/// 獲取目標對應的資料

///

/// 編碼

/// 數值 a b  30

/// 返回編號

/// 編碼

private string getvalue(encode p_code, string p_value, ref int p_setid)

///

/// 根據編號獲得條紋

///

///

///

private string getvalue(int p_codeid)

///

/// 獲得條碼圖形

///

/// 文字

/// 圖形

private bitmap getimage(string p_text)

bitmap _codeimage = new bitmap(_width, (int)m_height);

graphics _garphics = graphics.fromimage(_codeimage);

//pen _pen;

int _lenex = 0;

for (int i = 0; i != _value.length; i++)

else

//_garphics.(_pen, new point(_lenex, 0), new point(_lenex, m_height));

_lenex += _valuenumb;

} _garphics.dispose();

return _codeimage;

} ///

/// 顯示可見條碼文字 如果小於40 不顯示文字

///

/// 圖形

private void getviewtext(bitmap p_bitmap, string p_viewtext)

int _stary = p_bitmap.height - (int)_drawsize.height;

_graphics.fillrectangle(brushes.white, new rectangle(0, _stary, p_bitmap.width, (int)_drawsize.height));

_graphics.drawstring(p_viewtext, m_valuefont, brushes.black, (p_bitmap.width-_drawsize.width)/2, _stary);

} //12345678

//(105 + (1 * 12 + 2 * 34 + 3 * 56 + 4 *78)) % 103 = 47

//結果為starc +12 +34 +56 +78 +47 +end

internal image getcodeimage(string p) }

}呼叫方法

public void makebarcode(string sheetname)

}條形碼型別解釋:

生成條形碼

一 路由 routes.maproute name home url home getbar defaults new 二 html頁 text value id codenum button value 生成條形碼 onclick wds createbar width 200px height ...

Asp生成條形碼

function haiwaocde zfstr zf zfstr zf replace zf,0 zf replace zf,1 zf replace zf,2 zf replace zf,3 zf replace zf,4 zf replace zf,5 zf replace zf,7 zf r...

PHP生成條形碼

1.什麼是條形碼?列印出來的優惠券,商家需要用驗證器讀取條形碼,來獲得其有效性。2.如何生成條形碼?2.1檔案結構 2.2具體解析 1 class資料夾是已封裝好生成條形碼的類,只需要呼叫即可。2 index.php是乙個可選擇條件生成條形碼的功能,是主程式的入口,而html資料夾是提供的被引用的 ...