如何在RDLC报告c#中显示图像(内存流格式)?

时间:2014-07-18 06:48:53

标签: c# image dataset rdlc dynamic-rdlc-generation

我想在rdlc报告上显示条形码图像。

我使用以下代码获取该条形码图像的内存流。

https://www.nuget.org/packages/Aspose.BarCode/

安装了nuget
 /// 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();
        }

    }

后来我使用了这个内存流并发送到我在on 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()

出了什么问题?

0 个答案:

没有答案