We know that high-quality barcodes are better for our purposes, but the image dpi is proportional to the size of the image, the higher the DPI, the larger the picture file.
It may be easy for you to display a 600DPI picture in HTML, but you'll find that the picture fills the entire page because most of the HTML display resolution is 96DPI. Then today will be shared with barcode Professional for ASP. NET displays high-definition barcodes within the DPI range of HTML support. The code is for informational purposes only.
Note: We are using Visual Studio 2005 (Visual Web Developer), but some vs.net are also available.
Steps :
- Create an ASP. NET Web Project with Visual Studio 2005.
- Delete all the ASPX files created in the project.
- If there is a need to create a bin folder, add a reference to barcode Professional for ASP. NET collection.
- Add a new project type naming barcodegen.ashx in generic Handler.
- Enter the following code in the Barcodegen.ashx file using the ProcessRequest method, which will get the 128-yard symbol encoding value and the output barcode image resolution through a string query.
Vb
1 DimDpi as Single=96.02 3 Try4DPI = Single. Parse (context. Request.QueryString ("DPI"))5 Catch6 7 End Try8 9 DimValuetoencode as String= Context. Request.QueryString ("Valuetoencode")Ten One DimBcp as NewNeodynamic.WebControls.BarcodeProfessional.BarcodeProfessional () ABcp. Symbology =Neodynamic.WebControls.BarcodeProfessional.Symbology.Code128 -Bcp. Code =Valuetoencode - theBcp. BarWidth =0. 01F -Bcp. Barheight =0. 5F -Context. Response.ContentType ="Image/jpeg" -Context. Response.BinaryWrite (bcp. Getbarcodeimage (System.Drawing.Imaging.ImageFormat.Jpeg, DPI))
C#
1 floatDPI =96.0f;2 3 Try4 {5DPI =float. Parse (context. request.querystring["DPI"]);6 }7 Catch8 { }9 Ten stringValuetoencode = context. request.querystring["Valuetoencode"]; One ANeodynamic.WebControls.BarcodeProfessional.BarcodeProfessional bcp =NewNeodynamic.WebControls.BarcodeProfessional.BarcodeProfessional (); -Bcp. Symbology =Neodynamic.WebControls.BarcodeProfessional.Symbology.Code128; -Bcp. Code =Valuetoencode; the -Bcp. BarWidth =0.01f; -Bcp. Barheight =0.5f; - +Context. Response.ContentType ="Image/jpeg"; -Context. Response.BinaryWrite (bcp. Getbarcodeimage (System.Drawing.Imaging.ImageFormat.Jpeg, DPI));
- Then add the new item to the HTML page item, this HTML page will display the 600DPI barcode image, this is by using the JS code in other browsers to display the 96DPI HTTP processing. The following code is lost:
1 <!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd ">2 <HTMLxmlns= "http://www.w3.org/1999/xhtml" >3 <Head>4 <title>HTML Barcode image with DPI support</title>5 <Scripttype= "Text/javascript"> 6 varImageurlgen= "barcodegen.ashx";7 varImageID= "Mybarcodeimage";8 varTxtvaluetoencodeid= "Myvaluetoencode"; 9 varTmpimage;Ten varDPI= -; One A functioncheckforloadedimage () - { - if(Tmpimage.complete) the { - varimg=document.getElementById (ImageID); - Img.width=Tmpimage.width* the /dpi; - Img.height=Tmpimage.height* the /dpi; + img.src=tmpimage.src; - Cleartimeout ("checkforloadedimage ()"); + } A Else at { - setTimeout ("Checkforloadedimage ()", -); - } - } - - functiongetbarcodeimage () in { - varValuetoencode=document.getElementById (Txtvaluetoencodeid). value; to Tmpimage= NewImage (); + tmpimage.src=Imageurlgen+ "? valuetoencode=" +Valuetoencode+ "&dpi=" +dpi; - checkforloadedimage (); the } * </Script> $ </Head>Panax Notoginseng <Body> - <P> the <b>Barcode Professional in a HTML page with DPI support</b> + </P> A <P> the <imgID= "Mybarcodeimage"alt=""src="" /> + </P> - <P> $Enter a value to encode:<BR/> $ <inputID= "Myvaluetoencode"type= "text"name= "Myvaluetoencode" /> - </P> - <P> the <inputID= "Button1"type= "button"value= "Get Barcode at ..." - name= "Button1"onclick= "Getbarcodeimage ()" />Wuyi </P> the </Body> - </HTML>
Completed, although the image size is generated by the JS code, but the quality of the generated image is consistent with the printing results.
Barcode Professional for ASP. NET use Tutorial: How to display high-definition barcodes within the DPI range of HTML support