本文介绍了根据用户输入填写条形码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据用户输入成功打印BarCode,但BarCode未正确填充。图像高度和宽度随用户输入而增加/减少。



请参阅下面的参考图像。



[]



请建议根据用户输入填写条形码。



我尝试了什么:



I am trying to print the BarCode based on user input successfully, but the BarCode is not filling correctly. Image Height and Width is increasing/decreasing as user inputs.

Please see the below reference image.

Imgur: The magic of the Internet[^]

Please suggest filling the barcode based on user inputs.

What I have tried:

For these, I tried below code.







public void fun()
    {
        string barCode = txtCode.Text;
        System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebControls.Image();
        using (Bitmap bitMap = new Bitmap(Convert.ToInt32(txtW.Text), Convert.ToInt32(txtH.Text)))
        {
            using (Graphics graphics = Graphics.FromImage(bitMap))
            {
                Font oFont = new Font(@"C:\Users\bojjaiah.thoti\Downloads\IDAutomationCode39\IDAutomation.com Free Code 39 Font\IDAutomationHC39M.ttf", 16);
                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("*" + barCode + "*", 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 =  + Convert.ToBase64String(byteImage);

            }

            plBarCode.Controls.Add(imgBarCode);
        }
    }

推荐答案


这篇关于根据用户输入填写条形码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 04:28