国产99久久精品_欧美日本韩国一区二区_激情小说综合网_欧美一级二级视频_午夜av电影_日本久久精品视频

最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
當前位置: 首頁 - 科技 - 知識百科 - 正文

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

來源:懂視網 責編:小采 時間:2020-11-27 22:42:19
文檔

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

ASP.net(c#)生成條形碼 code39條碼生成方法:這幾天一直在弄128條碼的事情,找了相關的資料,也沒找到。后來沒辦法只能改成code39的條碼。現在把它寫出來,與大家分享1.先下載一種免費的 code39條碼字體 2.建個類 為 code39 并寫入以下代碼 代碼如下:public sealed class Code39 {
推薦度:
導讀ASP.net(c#)生成條形碼 code39條碼生成方法:這幾天一直在弄128條碼的事情,找了相關的資料,也沒找到。后來沒辦法只能改成code39的條碼。現在把它寫出來,與大家分享1.先下載一種免費的 code39條碼字體 2.建個類 為 code39 并寫入以下代碼 代碼如下:public sealed class Code39 {

這幾天一直在弄128條碼的事情,找了相關的資料,也沒找到。后來沒辦法只能改成code39的條碼。現在把它寫出來,與大家分享

1.先下載一種免費的 code39條碼字體
2.建個類 為 code39 并寫入以下代碼
代碼如下:


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 (條碼標簽)
/// </summary>
public string Label
{
set { _label = value; }
}
/// <summary>
/// BarCode Title Font (條碼標簽使用的字體)
/// </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
/// 附加信息,如果設置ShowBarCodeValue為true,則此項不顯示
/// </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
/// 是否在條碼下方顯示條碼值,默認為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
/// 條碼繪制的大小,默認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類型</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程序 請調用 CreateWebForm 如果是cs程序 則使用CreateWinForm
4.新建一aspx文件,寫入以下代碼
代碼如下:

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;
}

聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文檔

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

ASP.net(c#)生成條形碼 code39條碼生成方法:這幾天一直在弄128條碼的事情,找了相關的資料,也沒找到。后來沒辦法只能改成code39的條碼。現在把它寫出來,與大家分享1.先下載一種免費的 code39條碼字體 2.建個類 為 code39 并寫入以下代碼 代碼如下:public sealed class Code39 {
推薦度:
  • 熱門焦點

最新推薦

猜你喜歡

熱門推薦

專題
Top
主站蜘蛛池模板: 国产精品第一 | 精品久久久久久综合日本 | 黄片毛片一级 | 国产成人综合精品一区 | 午夜精品视频 | 欧美日韩综合精品一区二区三区 | 精品国产乱码久久久久久浪潮 | 性夜影院爽黄a爽免费看网站 | 一区二区免费播放 | 国产精品专区第二 | 国产经典一区 | 亚洲图片国产日韩欧美 | 中文字幕日韩一区二区三区不卡 | 国产一区二区三区免费观看 | 国产99久久亚洲综合精品 | 亚洲伊人久久大香线蕉综合图片 | 欧美中文娱乐网 | 黄网站免费在线观看 | 欧美亚洲日本国产 | a天堂专区一区二区三区 | 久久久久久久国产a∨ | 精品一区二区三区的国产在线观看 | 天天爱夜夜操 | 久久伊人一区二区三区四区 | 久久久久久久久久久9精品视频 | 久久久国产这里有的是精品 | 久久伊人精品一区二区三区 | 日韩视频中文字幕专区 | 亚洲国产精品一区二区三区 | 日韩不卡一区二区 | 国产精品成人69xxx免费视频 | 欧美成人禁片在线www | 香蕉视频免费在线看 | 日韩 国产 欧美 精品 在线 | 国产精品va一区二区三区 | 欧美成人国产 | 欧美日韩亚洲综合另类ac | 久久亚洲一级α片 | 一区高清 | 亚洲国产成人影院播放 | 在线播放国产精品 |