c# - C# Base64 字符串可以转换为图像但不显示在 .rdlc 图像控件中
问题描述
我使用了一个库来生成条形码位图,然后将其转换为 Base64 字符串。这个字符串工作正常,我可以在我找到的所有在线工具中将它转换回 Image。但是当我通过 Convert.FromBase64String() 将它放在 RDLC 报告中的图像控件上时,图像根本没有显示。
这是我的 base64 字符串(_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
谢谢。
解决方案
要Base64
在 RDLC 报表中将字符串显示为图像,请使用报表设计器:
- 从工具箱中删除
Image
报表控件。 - 右键单击图像并选择图像属性
- 将图像源设置为
Database
- 将 MIME 类型设置为合适的值,例如
image/bmp
. - 将此字段设置为您拥有的图像参数,例如 =
Parameters!MyImage.Value
。参数类型应该是Text
.
然后在运行时,将Base64
字符串分配为参数的值。
注意:当图像源设置为External
时,参数值应设置为绝对 URL,LocalReport.EnableExternalImages
报表查看器的属性应设置为true
。
推荐阅读
- python - (Python3)将对象传递给导入的模块函数
- powershell - 在我的 AD powershell 脚本中添加 Get-ADuser 属性时遇到问题
- javascript - 在 Sublime 3 中使用 underscore.js
- sql - DML 触发器可以用于警报吗?
- python - 从python列表中提取元素
- reactjs - 在 Webpack v3.8.1 中使用 resourceQuery
- kubernetes - Kubectl 补丁和 curl 补丁无法修补资源
- atom-editor - Atom 'Select Next' 不仅选择唯一出现的变量
- css - 奇数堆栈的最佳 CSS Flex 布局(桌面/移动)
- html - 为什么当我尝试使用它时我的下拉菜单关闭