{"id":2155,"date":"2017-09-15T14:28:55","date_gmt":"2017-09-15T14:28:55","guid":{"rendered":"http:\/\/galhano.com\/blog\/?p=2155"},"modified":"2017-09-15T14:31:15","modified_gmt":"2017-09-15T14:31:15","slug":"dynamically-generate-and-display-barcode-image-in-asp-net","status":"publish","type":"post","link":"http:\/\/galhano.com\/blog\/?p=2155","title":{"rendered":"Dynamically Generate and Display Barcode Image in ASP.Net"},"content":{"rendered":"<div>n this article I will explain how to dynamically generate and display barcode image using ASP.Net in C# and VB.Net languages.<\/div>\n<div><b>\u00a0<\/b><\/div>\n<div><b><u>Barcode Font<\/u><\/b><\/div>\n<div>First you will need to download the Free Barcode Font from the following URL<\/div>\n<div><a href=\"http:\/\/www.idautomation.com\/fonts\/free\/IDAutomationCode39.zip\">Download Barcode Font<\/a> or here <a href=\"http:\/\/galhano.com\/blog\/wp-content\/uploads\/2017\/09\/IDAutomationCode39.zip\">IDAutomationCode39<\/a><\/div>\n<div>Once downloaded follow the following steps.<\/div>\n<div>1. Extract the ZIP file.<\/div>\n<div>2. Click and Execute <b>INSTALL.exe<\/b> file.<\/div>\n<div>3. After installation is completed restart your machine.<\/div>\n<p>[html]<\/p>\n<p>&lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt;<br \/>\n&lt;asp:TextBox ID=&quot;txtCode&quot; runat=&quot;server&quot;&gt;&lt;\/asp:TextBox&gt;<br \/>\n&lt;asp:Button ID=&quot;btnGenerate&quot; runat=&quot;server&quot; Text=&quot;Generate&quot; onclick=&quot;btnGenerate_Click&quot; \/&gt;<\/p>\n<p>&lt;hr \/&gt;<\/p>\n<p>&lt;asp:PlaceHolder ID=&quot;plBarCode&quot; runat=&quot;server&quot; \/&gt;<br \/>\n&lt;\/form&gt;<\/p>\n<p>[\/html]<\/p>\n<p>&nbsp;<\/p>\n<p>[vb]<\/p>\n<p>Imports System.Drawing<br \/>\nImports System.Drawing.Imaging<br \/>\nImports System.IO<\/p>\n<p>[\/vb]<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>[vb]<\/p>\n<p>Protected Sub btnGenerate_Click(sender As Object, e As EventArgs)<br \/>\n    Dim barCode As String = txtCode.Text<br \/>\n    Dim imgBarCode As New System.Web.UI.WebControls.Image()<br \/>\n    Using bitMap As New Bitmap(barCode.Length * 40, 80)<br \/>\n        Using graphics__1 As Graphics = Graphics.FromImage(bitMap)<br \/>\n            Dim oFont As New Font(&quot;IDAutomationHC39M&quot;, 16)<br \/>\n            Dim point As New PointF(2.0F, 2.0F)<br \/>\n            Dim blackBrush As New SolidBrush(Color.Black)<br \/>\n            Dim whiteBrush As New SolidBrush(Color.White)<br \/>\n            graphics__1.FillRectangle(whiteBrush, 0, 0, bitMap.Width, bitMap.Height)<br \/>\n            graphics__1.DrawString(&quot;*&quot; &amp; barCode &amp; &quot;*&quot;, oFont, blackBrush, point)<br \/>\n        End Using<br \/>\n        Using ms As New MemoryStream()<br \/>\n            bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png)<br \/>\n            Dim byteImage As Byte() = ms.ToArray()<\/p>\n<p>            Convert.ToBase64String(byteImage)<br \/>\n            imgBarCode.ImageUrl = &quot;data:image\/png;base64,&quot; &amp; Convert.ToBase64String(byteImage)<br \/>\n        End Using<br \/>\n        plBarCode.Controls.Add(imgBarCode)<br \/>\n    End Using<br \/>\nEnd Sub<\/p>\n<p>[\/vb]<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/www.aspsnippets.com\/Articles\/Dynamically-Generate-and-Display-Barcode-Image-in-ASPNet.aspx\">https:\/\/www.aspsnippets.com\/Articles\/Dynamically-Generate-and-Display-Barcode-Image-in-ASPNet.aspx<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>n this article I will explain how to dynamically generate and display barcode image using ASP.Net in C# and VB.Net languages. \u00a0 Barcode Font First you will need to download the Free Barcode Font from the following URL Download Barcode Font or here IDAutomationCode39 Once downloaded follow the following steps. 1. Extract the ZIP file. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"close","ping_status":"close","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33,43,140],"tags":[],"class_list":["post-2155","post","type-post","status-publish","format-standard","hentry","category-code-snippets","category-netfx","category-vb","author-admin"],"_links":{"self":[{"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2155","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2155"}],"version-history":[{"count":3,"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2155\/revisions"}],"predecessor-version":[{"id":2159,"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2155\/revisions\/2159"}],"wp:attachment":[{"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2155"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2155"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2155"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}