简体   繁体   中英

How to show Image(memory stream format) on RDLC report c#?

I want to show barcode image on rdlc report.

I get a memory stream of that barcode image using following code.

Installed nuget from https://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();
        }

    }

and later on I used this memory stream and send to dataset which i used onside rdlc file.

in my .cs file code

   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());

in my rdlc code

in table used simple expression to access these values

=Fields!Number.Value
=Fields!BarcodeImage.Value

I can get Number correctly

But for BarcodeImage i'm getting value as System.ToArray()

what goes wrong?

Maybe you want to convert the Image to an Bitmap? something like

Bitmap image = barcode.GetOnlyBarCodeImage();

I cann't evaluate this, because when executing above code I have this error: "Sorry, evaluation version does not allow to generate such type of barcode's image."

old answer (rather a comment) - left for reference

could you provide the Class BarCodeBuilder() - can't evaluate the code without it :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM