我使用了条形码字体并使用代码128显示条形码,如何将此条形码保存为图像..

问题描述:

如何将条形码保存为图像?

How can I save the barcode as an image?

请查看下面提到的链接以获取更多信息。



Please check the below mentioned links for more info.

protected void btnGenerate_Click(object sender, EventArgs e)
{
    string barCode = txtCode.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);
    }
}





在ASP.Net中动态生成和显示条形码图像



生成条形码使用C#?




ASP.NET C#项目中的条形码生成