【发布时间】:2015-10-28 15:29:39
【问题描述】:
我正在尝试将条形码图像保存在数据库中。我的代码当前生成的只是一长串 URL。我的代码如下:
string barCode = ds.Tables[0].Rows[0]["productId"].ToString();
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("Free 3 of 9 Extended", 16);
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);
**// I think Problem is here, in these lines //**
lblChkCopyIMAge.Text = imgBarCode.ToString();
}
placehod.Controls.Add(imgBarCode);
}
请任何人帮助我将完整的条形码图像保存在特定文件夹中并在数据库中保存相应的 URL,以便我可以进一步使用它。上面写的代码只是生成条形码图像和一个长字符串 URL。当我将它保存在数据库中时,它会将这个字符串保存在 URL 中:“System.Web.UI.WebControls.Label”。我已经使用nvarchar(max) 数据类型来保存ImageURL。
我在数据库中保存的代码如下:
string strcmd5 = "update product set symbology=" + "'" + "IDAutomationHC39M" + "'" + "," + "barcodeimage=" + "'" + lblChkCopyIMAge + "'" + "where productId=" + int.Parse(Label1.Text);
SqlCommand objsqlcmd5 = new SqlCommand(strcmd5, objsqlcon4);
int h = objsqlcmd5.ExecuteNonQuery();
objsqlcon4.Close();
if (h > 0)
{
Response.Write("Record has submitted Successfully");
ScriptManager.RegisterStartupScript(this, this.GetType(), "barcode", "alert('Saved Successfully');", true);
}
【问题讨论】:
标签: c# asp.net image image-processing barcode