C# Base64 字符串可以转换为图像,但不显示在 .rdlc 图像控件中

标签 c# winforms base64 report rdlc

我使用一个库来生成条形码位图,然后将其转换为 Base64 字符串。这个字符串工作正常,我可以在我找到的所有在线工具中将其转换回图像。但是当我通过 Convert.FromBase64String() 将其放在 RDLC 报告中的图像控件上时,图像根本不显示。

这里是my base64 string (_sticker 即时中的 Base64Barcode)

然后我将此字符串传递给我的 ReportViewer(与我的 .rdlc 报告连接)

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

在 .rdlc 中,我创建一个图像控件并将“使用此图像”字段设置为:

=Convert.FromBase64String(Parameters!barcodeBase64.Value)

TextBox 控件工作正常。但图像控件只显示一个白色小框,里面有一个红色 X。

我在互联网上找到了很多解决方案,但似乎没有一个对我有用。有什么我错过的吗?

我使用 Visual Studio 2019 Community、.NET Framework 4.5、ZXing 库 0.16.4.0、Microsoft.ReportViewer.WinForms 14.0.0.0

谢谢。

最佳答案

要使用报表设计器在 RDLC 报表中将 Base64 字符串显示为图像:

  • 从工具箱中删除Image报表控件。
  • 右键单击图像并选择图像属性
  • 将图像源设置为数据库
  • 将 MIME 类型设置为合适的值,例如 image/bmp
  • 将此字段设置为您拥有的图像参数,例如 =Parameters!MyImage.Value。参数类型应为Text

然后在运行时,将 Base64 字符串指定为参数的值。

注意:当图片源设置为外部时,该参数的值应设置为绝对URL和LocalReport.EnableExternalImages报表查看器的属性应设置为 true

关于C# Base64 字符串可以转换为图像,但不显示在 .rdlc 图像控件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58077823/

相关文章:

c# - 从主窗体打开现有窗体

c - 指针初始化?对于特定功能

c# - 在多级树结构中搜索

c# - 如何获取 HttpRuntime.Cache 中对象的大小?

c# - 将项目添加到 DataGridViewComboBoxColumn

c# - 在 WinForms 中绑定(bind)到 WPF 托管控件的 DependencyProperty

java - 无法使 Guava base64 编码/解码工作

java - 将 double 组转换为字节数组 : What is the Java way of C# Buffer. BlockCopy?

c# - 使用 BackgroundWorker 更新 UI 而不会卡住......?

c# - Linq 到实体 : Count is very slow