locked
How to increase Barcode size RRS feed

  • Question

  • User1827380138 posted

    This is my Code

       <div class="panel-body">
              <div id="Barcode">
               <h1 align="center" 
                      style="text-decoration: underline; font-size: x-large; font-weight: bold">Barcode</h1>
    
                  <asp:Panel ID="Panel1" runat="server">
                      <asp:Label ID="lblPname" runat="server" Text="" Font-Bold="True"></asp:Label> 
                      <br />
                      <asp:PlaceHolder ID="phBarcode" runat="server"></asp:PlaceHolder>
                      </asp:Panel>
                  <div class="table-responsive";>
                     <table class="table">
                        <tbody>
                        <tr>
                        <td>
                            <asp:Button ID="btnPPdf" runat="server" Text="Print" CssClass="btn-info" 
                                Width="100px"/>
                        
                             <asp:Button ID="btnExcel" runat="server" Text="Excel" CssClass="btn-success" 
                                Width="100px" />
                        
                             <asp:Button ID="btnBack" runat="server" Text="Back" CssClass="btn-danger" 
                                Height="35px" Width="100px" />
                        </td>
                        </tr>
                        </tbody> 
                     </table>
                 </div>
              </div>
    
               </div>
     string var;
            protected void Page_Load(object sender, EventArgs e)
            {
                //lblPname.Text = Request.QueryString["pname"];
                //var = Request.QueryString["subhead"];
                lblPname.Text = "Raj";
                var = "G-212012";
                Barcode();
    
            }
            private void Barcode()
            {
                System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebControls.Image();
                using (Bitmap bitMap = new Bitmap(var.Length * 40,80))
                {
                    using (Graphics graphics = Graphics.FromImage(bitMap))
                    {
                        Font oFont = new Font("IDAutomationHC39M", 18);
                        PointF point = new PointF(2f, 2f);
                        SolidBrush blackBrush = new SolidBrush(Color.Black);
                        SolidBrush whiteBrush = new SolidBrush(Color.White);
                        graphics.FillRectangle(whiteBrush, 0, 0, bitMap.Width, bitMap.Height);
                        graphics.DrawString("*" + var + "*", oFont, blackBrush, point);
                    }
                    using (MemoryStream ms = new MemoryStream())
                    {
                        bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                        byte[] byteImage = ms.ToArray();
    
                        Convert.ToBase64String(byteImage);
                        imgBarCode.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(byteImage);
                    }
                    phBarcode.Controls.Add(imgBarCode);
                }
            }

    Saturday, December 28, 2019 3:01 PM

All replies

  • User-158764254 posted

    Increase the size of the bitmap - currently set to 40,80

    Increase the font size for the barcode font - currently set to 18

    Saturday, December 28, 2019 3:17 PM
  • User288213138 posted

    Hi Dhoni,

    Dhoni

    How to increase Barcode size

    Dhoni

    <h1 align="center" style="text-decoration: underline; font-size: x-large; font-weight: bold">Barcode</h1>

    Do you want to change the font size of Barcode? If yes, why not change by css style?

    Such as:

    <h1 align="center" style="text-decoration: underline; font-size: xx-large; font-weight: bold">Barcode</h1>

    If I misunderstand your requirement, please post more details information about your requirement.

    Best regards,

    Sam

    Monday, December 30, 2019 9:46 AM
  • User1827380138 posted

    When i change bitmap size it was not clear

    Tuesday, December 31, 2019 5:32 AM
  • User288213138 posted

    Hi Dhoni,

    When i change bitmap size it was not clear

    I don't understand what you mean? what is not clear?

    Bitmap encapsulates a GDI+ bitmap, which consists of the pixel data for a graphics image and its attributes.

    More information about the use of Bitmap you can refer to this link: https://docs.microsoft.com/en-us/dotnet/api/system.drawing.bitmap?view=netframework-4.8 

    Best regards,

    Sam

    Tuesday, December 31, 2019 8:12 AM