我想在 rdlc 报告上显示条形码图像。
我使用以下代码获得了该条形码图像的内存流。
从安装的 nugethttps://www.nuget.org/packages/Aspose.BarCode/
/// This function generates the QR code image using given string and returns the ImageByteArray
/// </summary>
/// <param name="QRCodeString">string from which the QR code Image will generate</param>
/// <param name="ImageWidth">Image Height</param>
/// <param name="ImageHeight">Image Width</param>
/// <param name="GetImageOnly">Set to true if you need only QR code image. Set to false if you need QR code image with code text below the image</param>
/// <returns></returns>
private MemoryStream GetQRCodeImage(string QRCodeString, int ImageWidth, int ImageHeight, bool GetImageOnly)
{
//Creating memory stream
System.IO.MemoryStream ms = new System.IO.MemoryStream();
try
{
Aspose.BarCode.BarCodeBuilder builder = new BarCodeBuilder();
//Set the Code text for the barcode
builder.CodeText = QRCodeString;
if (GetImageOnly)
{
// Set the code text location
builder.CodeLocation = CodeLocation.None;
//Get Only Imge
builder.GetOnlyBarCodeImage();
}
//Set the symbology type to
builder.SymbologyType = Symbology.QR;
builder.ImageHeight = ImageHeight;
builder.ImageWidth = ImageWidth;
//Saving barcode image to memory stream
builder.BarCodeImage.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
return ms;
}
catch (Exception ex)
{
throw;
}
finally
{
//Dont dispose here
// ms.Dispose();
}
}
后来我使用了这个内存流并发送到我在 rdlc 文件中使用的数据集。
在我的 .cs 文件代码中
DatasetName = "DemoDataset";
DataTable table1 = new DataTable("Details");
table1.Columns.Add("Number");
table1.Columns.Add("BarcodeImage");
MemoryStream barcode = new MemoryStream();
barcode = GetQRCodeImage("34526172", 600, 300, false);
table1.Rows.Add(12222, barcode.ToArray());
在我的 rdlc 代码中
在表中使用简单的表达式来访问这些值
=Fields!Number.Value
=Fields!BarcodeImage.Value
我可以正确获取号码
但是对于 BarcodeImage 我得到的价值是
System.ToArray()
出了什么问题?