我正在创建一个web应用程序,该应用程序生成使用数据绑定信息的条形码。该信息是来自数据库的名称。
条形码生成正确,但我想添加文本。
这是我的条形码生成器代码。
protected void btnGenerate_Click(object sender, EventArgs e)
{
foreach (ListItem item in BarCode.Items)
{
if (item.Selected)
{
string barCode = Barcode + txtCode.Text;
System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebControls.Image();
using (Bitmap bitMap = new Bitmap(barCode.Length * 50, 90))
{
using (Graphics graphics = Graphics.FromImage(bitMap))
{
Font oFont = new Font("IDAutomationHC39M", 18);
PointF point = new PointF(3f, 3f);
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);
}
}
}
}
我想添加
"数量:_____________"
生成时位于条形码下方。尽管我相信条形码的格式仅限于代码,而且我不相信我可以创建字符串文字
string lit = "QTY:_______________";
并将其添加到条形码字符串中:
string barCode = Barcode + txtCode.Text + Environement.NewLine + lit;
有可能通过编程将其添加到下面吗?
如果我理解得对你不需要在代码中添加文本,你需要在条形码下打印一些文本。只需添加到:
using (Graphics graphics
像这样的:
// put coordinates here:
RectangleF rectf = new RectangleF(70, 90, 90, 50);
graphics.DrawString(lit , new Font("Tahoma",8), Brushes.Black, rectf);