根据用户输入填写条形码 [英] Fill the barcode based on user input

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

问题描述

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



请参阅下面的参考图像。



Imgur:互联网的神奇之处 [ ^ ]



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



我尝试了什么:



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 = "data:image/png;base64," + Convert.ToBase64String(byteImage);

            }

            plBarCode.Controls.Add(imgBarCode);
        }
    }

推荐答案

您已设置位图的高度和宽度,以及起始位置文本,但您从未设置正在使用的字体的高度和宽度。
You have set the height and width of your bitmap, and the starting position of the text, but you never set the height and width of the font that you are using.


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆