最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

ASP.net(c#)生成條形碼 code39條碼生成方法

 更新時(shí)間:2012年11月24日 14:56:41   作者:  
這幾天一直在弄128條碼的事情,找了相關(guān)的資料,也沒(méi)找到。后來(lái)沒(méi)辦法只能改成code39的條碼,需要的朋友可以參考下
這幾天一直在弄128條碼的事情,找了相關(guān)的資料,也沒(méi)找到。后來(lái)沒(méi)辦法只能改成code39的條碼?,F(xiàn)在把它寫(xiě)出來(lái),與大家分享

1.先下載一種免費(fèi)的 code39條碼字體
2.建個(gè)類(lèi) 為 code39 并寫(xiě)入以下代碼
復(fù)制代碼 代碼如下:

public sealed class Code39
{
#region private variables
/// <summary>
/// The Space Between each of Title, BarCode, BarCodeString
/// </summary>
private const int SPACE_HEIGHT = 3;
SizeF _sizeLabel = SizeF.Empty;
SizeF _sizeBarCodeValue = SizeF.Empty;
SizeF _sizeBarCodeString = SizeF.Empty;
#endregion
#region Label
private string _label = null;
private Font _labelFont = null;
/// <summary>
/// BarCode Title (條碼標(biāo)簽)
/// </summary>
public string Label
{
set { _label = value; }
}
/// <summary>
/// BarCode Title Font (條碼標(biāo)簽使用的字體)
/// </summary>
public Font LabelFont
{
get
{
if (_labelFont == null)
return new Font("Arial", 10);
return _labelFont;
}
set { _labelFont = value; }
}
#endregion
private string _additionalInfo = null;
private Font _addtionalInfoFont = null;
/// <summary>
/// Additional Info Font (附加信息字體)
/// </summary>
public Font AdditionalInfoFont
{
set { _addtionalInfoFont = value; }
get
{
if (_addtionalInfoFont == null) return new Font("Arial", 10);
return _addtionalInfoFont;
}
}
/// <summary>
/// Additional Info Content, if "ShowBarCodeValue" is true, the info is unvisible
/// 附加信息,如果設(shè)置ShowBarCodeValue為true,則此項(xiàng)不顯示
/// </summary>
public string AdditionalInfo
{
set { _additionalInfo = value; }
}
#region BarCode Value and Font
private string _barCodeValue = null;
/// <summary>
/// BarCode Value (條碼值)
/// </summary>
public string BarCodeValue
{
get
{
if (string.IsNullOrEmpty(_barCodeValue))
throw new NullReferenceException("The BarCodeValue has not been set yet!");
return _barCodeValue;
}
set { _barCodeValue = value.StartsWith("*") && value.EndsWith("*") ? value : "*" + value + "*"; }
}
private bool _showBarCodeValue = false;
/// <summary>
/// whether to show the original string of barcode value bellow the barcode
/// 是否在條碼下方顯示條碼值,默認(rèn)為false
/// </summary>
public bool ShowBarCodeValue
{
set { _showBarCodeValue = value; }
}
private Font _barCodeValueFont = null;
/// <summary>
/// the font of the codestring to show
/// 條碼下方顯示的條碼值的字體
/// </summary>
public Font BarCodeValueFont
{
get
{
if (_barCodeValueFont == null)
return new Font("Arial", 10);
return _barCodeValueFont;
}
set { _barCodeValueFont = value; }
}
private int _barCodeFontSize = 50;
/// <summary>
/// the font size of the barcode value to draw
/// 條碼繪制的大小,默認(rèn)50
/// </summary>
public int BarCodeFontSzie
{
set { _barCodeFontSize = value; }
}
#endregion
#region generate the barcode image
private Bitmap BlankBackImage
{
get
{
int barCodeWidth = 0, barCodeHeight = 0;
using (Bitmap bmp = new Bitmap(1, 1, PixelFormat.Format32bppArgb))
{
using (Graphics g = Graphics.FromImage(bmp))
{
if (!string.IsNullOrEmpty(_label))
{
_sizeLabel = g.MeasureString(_label, LabelFont);
barCodeWidth = (int)_sizeLabel.Width;
barCodeHeight = (int)_sizeLabel.Height + SPACE_HEIGHT;
}
_sizeBarCodeValue = g.MeasureString(BarCodeValue, new Font("Free 3 of 9 Extended", _barCodeFontSize));
barCodeWidth = Math.Max(barCodeWidth, (int)_sizeBarCodeValue.Width);
barCodeHeight += (int)_sizeBarCodeValue.Height;
if (_showBarCodeValue)
{
_sizeBarCodeString = g.MeasureString(_barCodeValue, BarCodeValueFont);
barCodeWidth = Math.Max(barCodeWidth, (int)_sizeBarCodeString.Width);
barCodeHeight += (int)_sizeBarCodeString.Height + SPACE_HEIGHT;
}
//else
//{
// if (!string.IsNullOrEmpty(_additionalInfo))
// {
// _sizeAdditionalInfo = g.MeasureString(_additionalInfo, AdditionalInfoFont);
// barCodeWidth = Math.Max(barCodeWidth, (int)_sizeAdditionalInfo.Width);
// barCodeHeight += (int)_sizeAdditionalInfo.Height + SPACE_HEIGHT;
// }
//}
}
}
return new Bitmap(barCodeWidth, barCodeHeight, PixelFormat.Format32bppArgb);
}
}
/// <summary>
/// Draw the barcode value to the blank back image and output it to the browser
/// 繪制WebForm形式的條碼
/// </summary>
/// <param name="ms">Recommand the "Response.OutputStream" 使用 Response.OutputStream</param>
/// <param name="imageFormat">The Image format to the Browser 輸出到瀏覽器到圖片格式,建議GIF</param>
public Bitmap CreateWebForm(Stream ms, ImageFormat imageFormat)
{
int barCodeWidth, barCodeHeight;
using (Bitmap bmp = this.BlankBackImage)
{
barCodeHeight = bmp.Height;
barCodeWidth = bmp.Width;
using (Graphics g = Graphics.FromImage(bmp))
{
g.Clear(Color.White);
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
int vPos = 0;
////Draw Label String
if (!string.IsNullOrEmpty(_label))
{
g.DrawString(_label, LabelFont, new SolidBrush(Color.Black),
XCenter((int)_sizeLabel.Width, barCodeWidth), vPos);
vPos += (int)_sizeLabel.Height + SPACE_HEIGHT;
}
else { vPos = SPACE_HEIGHT; }
////Draw The Bar Value
g.DrawString(_barCodeValue, new Font("Free 3 of 9 Extended", _barCodeFontSize), new SolidBrush(Color.Black),
XCenter((int)_sizeBarCodeValue.Width, barCodeWidth), vPos);
////Draw the BarValue String
if (_showBarCodeValue)
{
g.DrawString(_barCodeValue, BarCodeValueFont, new SolidBrush(Color.Black),
XCenter((int)_sizeBarCodeString.Width, barCodeWidth),
vPos + (int)_sizeBarCodeValue.Height);
}
//else
//{
// if (!string.IsNullOrEmpty(_additionalInfo))
// {
// g.DrawString(_additionalInfo, AdditionalInfoFont, new SolidBrush(Color.Black),
// XCenter((int)_sizeAdditionalInfo.Width, barCodeWidth),
// vPos + (int)_sizeBarCodeValue.Height);
// }
//}
}
bmp.Save(ms, imageFormat);
return bmp;
}
}
/// <summary>
/// 生成winform格式的條碼
/// </summary>
/// <param name="imageFormat">圖片格式,建議GIF</param>
/// <returns>Stream類(lèi)型</returns>
public Stream CreateWinForm(ImageFormat imageFormat)
{
int barCodeWidth, barCodeHeight;
using (Bitmap bmp = this.BlankBackImage)
{
barCodeHeight = bmp.Height;
barCodeWidth = bmp.Width;
using (Graphics g = Graphics.FromImage(bmp))
{
g.Clear(Color.White);
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
int vPos = 0;
////Draw Label String
if (!string.IsNullOrEmpty(_label))
{
g.DrawString(_label, LabelFont, new SolidBrush(Color.Black),
XCenter((int)_sizeLabel.Width, barCodeWidth), vPos);
vPos += (int)_sizeLabel.Height + SPACE_HEIGHT;
}
else { vPos = SPACE_HEIGHT; }
////Draw The Bar Value
g.DrawString(_barCodeValue, new Font("Free 3 of 9 Extended", _barCodeFontSize), new SolidBrush(Color.Black),
XCenter((int)_sizeBarCodeValue.Width, barCodeWidth), vPos);
////Draw the BarValue String
if (_showBarCodeValue)
{
g.DrawString(_barCodeValue, BarCodeValueFont, new SolidBrush(Color.Black),
XCenter((int)_sizeBarCodeString.Width, barCodeWidth),
vPos + (int)_sizeBarCodeValue.Height);
}
//else
//{
// //if (!string.IsNullOrEmpty(_additionalInfo))
// //{
// // g.DrawString(_additionalInfo, AdditionalInfoFont, new SolidBrush(Color.Black),
// // //XCenter((int)_sizeAdditionalInfo.Width, barCodeWidth),
// // vPos + (int)_sizeBarCodeValue.Height);
// //}
//}
}
Stream ms = new MemoryStream();
bmp.Save(ms, imageFormat);
return ms;
}
}
#endregion
private static int XCenter(int subWidth, int globalWidth)
{
return (globalWidth - subWidth) / 2;
}
}

3.如果是web程序 請(qǐng)調(diào)用 CreateWebForm 如果是cs程序 則使用CreateWinForm
4.新建一aspx文件,寫(xiě)入以下代碼
復(fù)制代碼 代碼如下:

protected void Page_Load(object sender, EventArgs e)
{
Code39 code39 = new Code39();
code39.BarCodeValue = "LDSO-001";
code39.BarCodeFontSzie = 60;
// code39.Label = "39碼,底部顯示碼值";
code39.ShowBarCodeValue = true;
Response.Write(code39.CreateWebForm(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif));
code39 = null;
}

相關(guān)文章

  • asp.net AjaxControlToolKit--TabContainer控件的介紹

    asp.net AjaxControlToolKit--TabContainer控件的介紹

    ModalPopup控件允許一個(gè)asp頁(yè)面的部分內(nèi)容以對(duì)話框的模式顯示給用戶,同時(shí)會(huì)限制用戶于頁(yè)面的其他部分交互。對(duì)話框顯示的內(nèi)容可以是一個(gè)層級(jí),這個(gè)層級(jí)的背景可以使用戶自定義的格式,簡(jiǎn)單的理解好比是一個(gè)對(duì)話框彈出來(lái)后,主頁(yè)面會(huì)顯示灰色,且不可操作。
    2009-06-06
  • asp.Net 中獲取一周第一天,一月第一天等實(shí)現(xiàn)代碼

    asp.Net 中獲取一周第一天,一月第一天等實(shí)現(xiàn)代碼

    .Net中獲取一周第一天、最后一天,一月第一天、最后一天
    2009-12-12
  • 在Asp.net core中實(shí)現(xiàn)websocket通信

    在Asp.net core中實(shí)現(xiàn)websocket通信

    這篇文章介紹了在Asp.net core中實(shí)現(xiàn)websocket通信的方法,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-07-07
  • .NET 6開(kāi)發(fā)TodoList應(yīng)用實(shí)現(xiàn)結(jié)構(gòu)搭建

    .NET 6開(kāi)發(fā)TodoList應(yīng)用實(shí)現(xiàn)結(jié)構(gòu)搭建

    這篇文章主要介紹了.NET 6開(kāi)發(fā)TodoList應(yīng)用實(shí)現(xiàn)結(jié)構(gòu)搭建,上一篇我們講解了實(shí)現(xiàn)系列背景 ,今天繼續(xù)來(lái)講講.NET 6開(kāi)發(fā)TodoList并且實(shí)現(xiàn)結(jié)構(gòu)搭建,更多詳細(xì)內(nèi)容剛興趣得小伙伴可以來(lái)參考一下下面文章得具體內(nèi)容
    2021-12-12
  • 利用.net core實(shí)現(xiàn)反向代理中間件的方法

    利用.net core實(shí)現(xiàn)反向代理中間件的方法

    這篇文章主要給大家介紹了關(guān)于利用.net core實(shí)現(xiàn)反向代理中間件的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用.net core具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-09-09
  • ASP.NET開(kāi)源導(dǎo)入導(dǎo)出庫(kù)Magicodes.IE完成Csv導(dǎo)入導(dǎo)出的方法

    ASP.NET開(kāi)源導(dǎo)入導(dǎo)出庫(kù)Magicodes.IE完成Csv導(dǎo)入導(dǎo)出的方法

    這篇文章主要介紹了ASP.NET開(kāi)源導(dǎo)入導(dǎo)出庫(kù)Magicodes.IE完成Csv導(dǎo)入導(dǎo)出的方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-06-06
  • 在ASP.NET中用MSDNURLRewriting實(shí)現(xiàn)Url Rewriting

    在ASP.NET中用MSDNURLRewriting實(shí)現(xiàn)Url Rewriting

    在ASP.NET中用MSDNURLRewriting實(shí)現(xiàn)Url Rewriting...
    2007-03-03
  • php使用socket編程示例

    php使用socket編程示例

    這篇文章主要介紹了php使用socket編程的示例,大家參考使用吧
    2014-01-01
  • WinForm中窗體間的數(shù)據(jù)傳遞交互的一些方法

    WinForm中窗體間的數(shù)據(jù)傳遞交互的一些方法

    通過(guò)子窗口向外引發(fā)一個(gè)事件,父窗口去實(shí)現(xiàn)該事件,我們可以再不關(guān)閉父窗口和子窗口的情況下進(jìn)行數(shù)據(jù)的傳輸顯示
    2012-12-12
  • ASP.NET如何使用web服務(wù)的會(huì)話狀態(tài)

    ASP.NET如何使用web服務(wù)的會(huì)話狀態(tài)

    這篇文章主要介紹了ASP.NET如何使用web服務(wù)的會(huì)話狀態(tài),使用一個(gè)GridView中的會(huì)話對(duì)象來(lái)展示最近的計(jì)算結(jié)果,感興趣的小伙伴們可以參考一下
    2015-11-11

最新評(píng)論

虹口区| 荔浦县| 英德市| 青海省| 嫩江县| 永嘉县| 庐江县| 淮安市| 拜泉县| 玉环县| 天镇县| 垣曲县| 黎平县| 沙湾县| 三都| 河东区| 固原市| 呈贡县| 荣昌县| 南昌市| 涞源县| 南投市| 宁乡县| 巴彦淖尔市| 缙云县| 任丘市| 湖南省| 商都县| 普安县| 肇州县| 赤水市| 芜湖县| 宜川县| 保康县| 蒲城县| 邵武市| 兴仁县| 新巴尔虎右旗| 唐山市| 贵溪市| 海宁市|