原創|使用教程|編輯:龔雪|2015-11-19 16:50:27.000|閱讀 524 次
概述:本教程是關于在Barcode Professional for ASP.NET指定區域條碼的顯示,使用GetBarcodeImage()從而達到目的。附有C#和VB代碼
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
需求:
由于條件的限制,條碼顯示位置有限,那么就需要懂得規定的區域內顯示條碼方法。今天將給大家簡單介紹如何在規定區域內顯示條碼。
【Barcode Professional for ASP.NET下載】
我們知道在Barcode Professional有GetBarcodeImage()方法,而這種方法可以通過barsAreaSizeInInches參數實現規定區域內條碼的顯示。現在我們需注意以下三點:
假定:編碼的數據是1234567890,使用128代碼,以300DPI呈現,可供條碼顯示的位置面積是1*0.5英寸.
參考代碼:
VB
Private Sub SaveBarcode() 'Create a Barcode Professional object Dim bcp As New Neodynamic.WebControls.BarcodeProfessional.BarcodeProfessional() 'Set the barcode symbology to Code 128 bcp.Symbology = Neodynamic.WebControls.BarcodeProfessional.Symbology.Code128 'Set the value to encode bcp.Code = "1234567890" 'Barcode dimensions settings bcp.BarHeight = 1.0F bcp.BarWidth = 0.01F 'Resolution Dim dpi As Single = 300.0F 'Target size in inches Dim targetArea As New System.Drawing.SizeF(1.0F, 0.5F) 'Get the barcode image fitting the target area Dim imgBarcode As System.Drawing.Image = bcp.GetBarcodeImage(dpi, targetArea) 'Save it on disk in PNG format imgBarcode.Save("C:\temp\barcode128.png", System.Drawing.Imaging.ImageFormat.Png) imgBarcode.Dispose() End Sub
C#
private void SaveBarcode() { //Create a Barcode Professional object Neodynamic.WebControls.BarcodeProfessional.BarcodeProfessional bcp = new Neodynamic.WebControls.BarcodeProfessional.BarcodeProfessional(); //Set the barcode symbology to Code 128 bcp.Symbology = Neodynamic.WebControls.BarcodeProfessional.Symbology.Code128; //Set the value to encode bcp.Code = "1234567890"; //Barcode dimensions settings bcp.BarHeight = 1.0f; bcp.BarWidth = 0.01f; //Resolution float dpi = 300.0f; //Target size in inches System.Drawing.SizeF targetArea = new System.Drawing.SizeF(1.0f, 0.5f); //Get the barcode image fitting the target area System.Drawing.Image imgBarcode = bcp.GetBarcodeImage(dpi, targetArea); //Save it on disk in PNG format imgBarcode.Save(@"C:\temp\barcode128.png", System.Drawing.Imaging.ImageFormat.Png); imgBarcode.Dispose(); }
需要注意的是目標寬度是整個條碼欄寬度加上左右兩邊的Quiet Zones (QuietZoneWidth屬性 ),然而目標區域高度僅僅只是條碼欄的高度,可參考下圖(前面代碼生成)。
如果只想條碼布滿整個目標區域,需要將QuietZoneWidth屬性設置為0(即除去左右兩邊的邊距)DisplayCode屬性設置為False(即隱藏可讀文本),可參考下列代碼
VB
Private Sub SaveBarcode() 'Create a Barcode Professional object Dim bcp As New Neodynamic.WebControls.BarcodeProfessional.BarcodeProfessional() 'Set the barcode symbology to Code 128 bcp.Symbology = Neodynamic.WebControls.BarcodeProfessional.Symbology.Code128 'Set the value to encode bcp.Code = "1234567890" 'Barcode dimensions settings bcp.BarHeight = 1.0F bcp.BarWidth = 0.01F bcp.QuietZoneWidth = 0 bcp.DisplayCode = False 'Resolution Dim dpi As Single = 300.0F 'Target size in inches Dim targetArea As New System.Drawing.SizeF(1.0F, 0.5F) 'Get the barcode image fitting the target area Dim imgBarcode As System.Drawing.Image = bcp.GetBarcodeImage(dpi, targetArea) 'Save it on disk in PNG format imgBarcode.Save("C:\temp\barcode128_full.png", System.Drawing.Imaging.ImageFormat.Png) imgBarcode.Dispose() End Sub
C#
private void SaveBarcode() { //Create a Barcode Professional object Neodynamic.WebControls.BarcodeProfessional.BarcodeProfessional bcp = new Neodynamic.WebControls.BarcodeProfessional.BarcodeProfessional(); //Set the barcode symbology to Code 128 bcp.Symbology = Neodynamic.WebControls.BarcodeProfessional.Symbology.Code128; //Set the value to encode bcp.Code = "1234567890"; //Barcode dimensions settings bcp.BarHeight = 1.0f; bcp.BarWidth = 0.01f; bcp.QuietZoneWidth = 0; bcp.DisplayCode = false; //Resolution float dpi = 300.0f; //Target size in inches SizeF targetArea = new System.Drawing.SizeF(1.0f, 0.5f); //Get the barcode image fitting the target area System.Drawing.Image imgBarcode = bcp.GetBarcodeImage(dpi, targetArea); //Save it on disk in PNG format imgBarcode.Save(@"C:\temp\barcode128_full.png", System.Drawing.Imaging.ImageFormat.Png); imgBarcode.Dispose(); }
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn