Reputation: 105
I used a library to generate Barcode Bitmap and then convert this to Base64 string. This string works ok, I can convert it back to Image in all online tools I found. But when I put it on an Image control in RDLC report by Convert.FromBase64String(), the Image not showing at all.
Here is my base64 string (Base64Barcode in _sticker instant)
Then I pass this string to my ReportViewer (connected with my .rdlc report)
private void FormPreview_Load(object sender, EventArgs e)
{
ReportParameter[] parameters = new ReportParameter[]
{
new ReportParameter("palletNo", _sticker.PalletNo)
new ReportParameter("qrBase64", _sticker.Base64QR, true),
new ReportParameter("barcodeBase64", _sticker.Base64Barcode, true)
};
this.reportViewer.LocalReport.SetParameters(parameters);
this.reportViewer.RefreshReport();
}
In .rdlc I create an Image control and set the field "Use this image" to:
=Convert.FromBase64String(Parameters!barcodeBase64.Value)
The TextBox control works fine. But Image controls do not show anything but a white little box with a red X inside.
I've found many solutions on the internet but none of them seems works to me. Is there something that I missed?
I use Visual Studio 2019 Community, .NET Framework 4.5, ZXing library 0.16.4.0, Microsoft.ReportViewer.WinForms 14.0.0.0
Thanks.
Upvotes: 2
Views: 4576
Reputation: 125197
To show a Base64
string as image in the RDLC report, using report designer:
Image
report control from toolbox.Database
image/bmp
.Parameters!MyImage.Value
. The parameter type should be Text
.Then at run-time, assign the Base64
string as value of the parameter.
Note: When the image source is set to External
, the value of the parameter should set to an absolute URL and the LocalReport.EnableExternalImages
property of the report viewer should be set to true
.
Upvotes: 5