技术:Visual Studio 2010 和 Crystal Reports、MVC3 Web 应用程序、多层应用程序。
我的网络应用程序构建了一份报告来标记打印。该报告工作正常,但不生成条形码。当我查看报告时,条形码字段为空白。我已经安装了 IDAutomationHC39M 并在 winforms 项目中工作。
生成报告的代码:
public void Barcode()
{
BarCode report = new BarCode();
Barcodes barcodeDetails = new Barcodes();
DataTable dataTable = barcodeDetails._Barcodes;
for (int i = 0; i < 80; i++)
{
DataRow row = dataTable.NewRow();
string nome = "nome" + i;
decimal preco = i;
string barcode = i + "ADF" + i;
row["nome"] = nome;
row["preco"] = preco;
row["barcode"] = barcode;
dataTable.Rows.Add(row);
}
report.Database.Tables["Barcodes"].SetDataSource((DataTable)dataTable);
report.ExportToHttpResponse(ExportFormatType.PortableDocFormat, System.Web.HttpContext.Current.Response, false, "crReport");
}
在 jpeg 中转换条形码更容易吗?如果是的话,我怎样才能在水晶报告中做到这一点?
EDI I:我尝试更改以下代码:
for (int i = 0; i < 80; i++)
{
DataRow row = dataTable.NewRow();
string nome = "nome" + i;
decimal preco = i;
string barcode = "*" + i + "ADF" + i + "*";
row["nome"] = nome;
row["preco"] = preco;
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", 10);
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);
row["barcode"] = imgBarCode.ImageUrl;
}
}
dataTable.Rows.Add(row);
}
但是没有效果。