Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
未在C#web表单中生成条形码?_C#_Asp.net_Web - Fatal编程技术网

未在C#web表单中生成条形码?

未在C#web表单中生成条形码?,c#,asp.net,web,C#,Asp.net,Web,我正在尝试在我的web表单中创建条形码。为此,我下载fontIDAutomationHC39M并安装到我的系统中,然后在localhost中运行我的wesite,但无法生成条形码。这是我的代码 protected void Button1_Click1(object sender, EventArgs e) { string barCode = TextBox1.Text; System.Web.UI.WebControls.Image imgBarCo

我正在尝试在我的web表单中创建条形码。为此,我下载fontIDAutomationHC39M并安装到我的系统中,然后在localhost中运行我的wesite,但无法生成条形码。这是我的代码

 protected void Button1_Click1(object sender, EventArgs e)
    {
        string barCode = TextBox1.Text;
        System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebControls.Image();
        using (Bitmap bitMap = new Bitmap(barCode.Length * 40, 80))
        {
            using (Graphics graphics = Graphics.FromImage(bitMap))
            {
                Font oFont = new Font("IDAutomationHC39M", 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);
        }

结果显示为代码

如果您能更详细地描述问题所在,可能会有帮助,可以附加输出图像?当我输入字符串ABCD123时,我得到的条形码为ABCD123Font OFNT=new Font(“IDAutomationHC39M”,16);此代码不适用于正在运行的WPF进程的字体?意思:你可能需要完全信任才能看到机器上的字体库——也许WPF正在挑选下一个最合适的,老实说,这可能和你想要的条形码完全不同!