Base64 图像不显示在 RDLC 报告中的 Render PDF 上

Base64 image doesn#39;t display on Render PDF from RDLC report(Base64 图像不显示在 RDLC 报告中的 Render PDF 上)

本文介绍了Base64 图像不显示在 RDLC 报告中的 Render PDF 上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 RDLC 报告中使用参数(@CustomerSign)显示图像(base64 字符串)(我正在从报告中呈现 PDF 文件,我正在查看 PDF 文件)

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)

使用此 MIME 类型:image/png

Use this MIME type: image/png

并传递参数:

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

但是图像显示红色十字 [X] 而不是图像,并且不会出错!

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

可能是什么问题?

我也尝试过:如何将 PNG 图像(作为内存流)渲染到 .NET ReportViewer 报表表面

推荐答案

首先,检查 Visual Studio 输出窗口.调试时出现的任何 RDLC 错误都应该出现在此处.

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

例如,我收到一条错误消息,提示我传递了无效的 base64 字符串.

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

如果你看到:

警告:图像Image"的 ImageData 属性值为=Convert.From...",这不是有效的 ImageData.(rsInvalidDatabaseImageProperty)

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.

在我的情况下,按照您使用的模式(谢谢),我的问题最终是我在数据库中的 base64 以 data:image/png;base64, 为前缀,因为它是从 html 图像元素中提取和写入.

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.

要删除该前缀,我的 RDLC 表达式变为:

To remove that prefix turned my RDLC expression to:

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

我的建议是从数据库中提取一个 base 64 字符串,并确认它确实可以作为图像工作.尝试将其放入 base64 图像查看器(例如:https://codebeautify.org/base64-图像转换器).(尽管在我的情况下,我想这不会有帮助,因为即使使用该前缀,该网站仍然可以工作.)

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.)

这篇关于Base64 图像不显示在 RDLC 报告中的 Render PDF 上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Base64 图像不显示在 RDLC 报告中的 Render PDF 上

基础教程推荐