原創|使用教程|編輯:龔雪|2015-11-09 16:33:09.000|閱讀 409 次
概述:分享用Barcode Professional for ASP.NET在HTML支持的DPI范圍內顯示高清條碼,含有C#和VB兩種參考代碼
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
我們知道高質量的條碼更能達到我們的目的,然而圖像DPI與圖像的大小成正比,即DPI越高,圖片文件越大。

可能你將600DPI的圖片顯示在HTML上很容易,然而你會發現圖片占滿了整個頁面,因為大多數的HTML顯示分辨率為96DPI。那么今天將分享用Barcode Professional for ASP.NET在HTML支持的DPI范圍內顯示高清條碼。代碼僅供參考。
注意:我們使用的是Visual Studio 2005 (Visual Web Developer) ,不過有些VS.NET也可以使用。
步驟:
VB
Dim dpi As Single = 96.0
 
 Try
 dpi = Single.Parse(context.Request.QueryString("dpi"))
 Catch
 
 End Try
 
 Dim valueToEncode As String = context.Request.QueryString("valueToEncode")
 
 Dim bcp As New Neodynamic.WebControls.BarcodeProfessional.BarcodeProfessional()
 bcp.Symbology = Neodynamic.WebControls.BarcodeProfessional.Symbology.Code128
 bcp.Code = valueToEncode
 
 bcp.BarWidth = 0.01F
bcp.BarHeight = 0.5F
context.Response.ContentType = "image/jpeg"
 context.Response.BinaryWrite(bcp.GetBarcodeImage(System.Drawing.Imaging.ImageFormat.Jpeg, dpi))C#
float dpi = 96.0f;
 
 try
 {
 dpi = float.Parse(context.Request.QueryString["dpi"]);
 }
 catch
 { }
 
 string valueToEncode = context.Request.QueryString["valueToEncode"];
 
 Neodynamic.WebControls.BarcodeProfessional.BarcodeProfessional bcp = new Neodynamic.WebControls.BarcodeProfessional.BarcodeProfessional();
 bcp.Symbology = Neodynamic.WebControls.BarcodeProfessional.Symbology.Code128;
 bcp.Code = valueToEncode;
 
 bcp.BarWidth = 0.01f;
 bcp.BarHeight = 0.5f;
 
 context.Response.ContentType = "image/jpeg";
context.Response.BinaryWrite(bcp.GetBarcodeImage(System.Drawing.Imaging.ImageFormat.Jpeg, dpi));<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "//www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="//www.w3.org/1999/xhtml" >
 <head>
 <title>HTML Barcode image with DPI support</title>
 <script type="text/javascript"> 
 var imageUrlGen = "BarcodeGen.ashx";
 var imageID = "MyBarcodeImage";
 var txtValueToEncodeID = "MyValueToEncode"; 
 var tmpImage;
 var dpi = 600;
 
 function CheckForLoadedImage()
 {
 if(tmpImage.complete)
 {
 var img = document.getElementById(imageID); 
 img.width = tmpImage.width * 96 / dpi;
 img.height = tmpImage.height * 96 / dpi; 
 img.src = tmpImage.src; 
 clearTimeout("CheckForLoadedImage()");
 }
 else
 {
 setTimeout(“checkforloadedimage()”,500);
 } 
 }
 
 function GetBarcodeImage()
 {
 var valueToEncode = document.getElementById(txtValueToEncodeID).value; 
 tmpImage = new Image();
 tmpImage.src = imageUrlGen + "?valueToEncode="  + valueToEncode + "&dpi=" + dpi; 
 CheckForLoadedImage();
 } 
 </script>
 </head>
 <body>
 <p>
 <b>Barcode Professional in a HTML page with DPI support</b>
 </p>
 <p>
 <img id="MyBarcodeImage" alt="" src="" />
 </p>
 <p>
 Enter a value to encode:<br />
 <input id="MyValueToEncode" type="text" name="MyValueToEncode" />
 </p>
 <p>
 <input id="Button1" type="button" value="Get Barcode at 600 DPI..."
 name="Button1" onclick="GetBarcodeImage()" />
 </p>
 </body>
</html>完成,雖然圖像的大小是經過JS代碼生成的,但生成圖像的質量是與打印結果一致。
Barcode Professional for ASP.NET>>
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@ke049m.cn