12

I'm trying to display image(base64 string) using parameter(@CustomerSign) in RDLC report (I'm rendering PDF file from report and I'm seeing PDF file)

I've configured image property as below:

Select the image source : Database
Use this field :

=Convert.FromBase64String(Parameters!CustomerSign.Value)

Use this MIME type: image/png

And passing parameter:

ReportParameter CustomerSign = new ReportParameter("CustomerSign", obj.SignImage);
rptvw.LocalReport.SetParameters(CustomerSign);

But the image showing red Cross [X] instead of image, and doesn't gives an error!

What could be the issue?

I've also tried: How can I render a PNG image (as a memory stream) onto a .NET ReportViewer report surface

Community
  • 1
  • 1
Hina Khuman
  • 757
  • 3
  • 14
  • 41
  • I don't understand why you are using a base64 string parameter: what is the source of this image? is it in a database or in file system? – tezzo Feb 03 '17 at 10:54
  • @tezzo: yes..it's database – Hina Khuman Feb 03 '17 at 11:01
  • what dbms are you using? is your image stored as base64 string or in another format (i.e.: blob, image)? can you pass this image using DataSources (not tested but it is very strange that you can set source = database and then value = parameter)? – tezzo Feb 03 '17 at 11:16
  • @tezzo: I'm using MS SQL Server, yes my image stored as base64 string, okay let me give a try to set DataSource – Hina Khuman Feb 03 '17 at 11:19
  • @tezzo: but how can use DataSource ? – Hina Khuman Feb 03 '17 at 11:20
  • give a look here: https://msdn.microsoft.com/en-us/library/microsoft.reporting.winforms.reportdatasource.aspx – tezzo Feb 03 '17 at 13:24
  • @tezzo: I've already one data source, how can I use second Datasource for just getting image?? – Hina Khuman Mar 21 '17 at 07:52

3 Answers3

2

Support for images is pretty limited, this MSDN article discusses what you can do.

Seems somewhat obvious from the question that embedding them in the report is not an option. But you can specify an external dbase as a source. Beware the EnableExternalImages property you have to set, as documented by the MSDN article. Seems the way to go, the question is not detailed enough, you might have to provide a suitable table with the desired image in your code.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • There is no option of *external dbase* as a *source* Please check in linked article. – Hina Khuman Mar 20 '17 at 10:44
  • 2
    I think you are confusing the External option with the Database option. External is tricky because it means using a URL. The OP is asking about using the Database option which is binding to a report field or parameter. – Dave Cousineau Aug 06 '17 at 02:01
2

First, check the Visual Studio output window. Any RDLC errors that you get should appear there when debugging.

For example, I was getting an error saying that I was passing an invalid base64 string.

If you see:

Warning: The value of the ImageData property for the image ‘Image’ is “=Convert.From...”, which is not a valid ImageData. (rsInvalidDatabaseImageProperty)

this seems to mean that an exception was thrown and so the expression did not evaluate and was passed as raw text (and so this message says that the raw text is not valid image data). The previous line in the output window should contain the actual error that caused the problem.

In my case, following the pattern that you are using (thanks), my problem ended up being that my base64 in the database was prefixed with data:image/png;base64, since it was being pulled from and written to an html image element.

To remove that prefix turned my RDLC expression to:

=Convert.FromBase64String(CStr(Parameters!Base64.Value).Substring(22))

What I would suggest is pulling a base 64 string out of the database and confirm that it does actually work as an image. Try putting it into a base64 image viewer (for example: https://codebeautify.org/base64-to-image-converter). (Although in my case I guess that wouldn't have helped since that site still works even with that prefix.)

Dave Cousineau
  • 12,154
  • 8
  • 64
  • 80
1
=System.Convert.FromBase64String(Parameters!Logo.Value)
Hasan Shouman
  • 2,162
  • 1
  • 20
  • 26