【发布时间】:2018-10-10 16:35:40
【问题描述】:
我有这个代码用于在页面加载时生成条形码。(下面的代码)txtBarcodeBlack.Text 内容从 SQL Server 数据库中提取为 varchar。 我有一个按钮提交,它将执行另一个过程,例如将 txtBarcodeBlack.text 保存到数据库。我的问题是当我按下按钮时,它给了我这个Problem 请帮忙。我被困了 2 天。
private void loadBlackBarcode() {
//barcode black
//txtBarcodeBlack.Text = vBarcodeBlack;
string barCodeBlack = txtBarcodeBlack.Text;
System.Web.UI.WebControls.Image imgBarCodeBlack = new System.Web.UI.WebControls.Image();
using (Bitmap bitMap = new Bitmap(barCodeBlack.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("*" + barCodeBlack + "*", oFont, blackBrush, point);
}
using (MemoryStream ms = new MemoryStream(100000))
{
bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
byte[] byteImage = ms.ToArray();
Convert.ToBase64String(byteImage);
imgBarCodeBlack.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(byteImage);
}
PlaceHolder1.Controls.Add(imgBarCodeBlack);
}
}
<div class="col-xs-12 col-sm-12 col-lg-12" style="margin-bottom:20px;">
<h3>Digital Black</h3>
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
</div>
【问题讨论】:
-
只是猜测:也许
barCodeBlack.Length等于零。我想将零传递给Bitmapctor 会导致该错误。 -
我试了调试,把这个barCodeBlack.Length;它显示 20. 表示它有长度。接下来我该怎么办?
-
这是我唯一的猜测,抱歉。