如何在Microsoft报表中显示来自字节数组的图像 [英] How to show Image from byte array in Microsoft report
问题描述
我正在使用Report文件和ReportViewer控件来显示一个报告,该报告在运行时动态地从对象加载数据。
I am using a Report file and a ReportViewer control to show a report which loads data dynamically from objects during run-time.
我需要显示一个图像在对象中存储为字节数组。
I need to show an image which is stored as a byte array in the object.
PictureBox的值当前设置为:
The PictureBox's value is currently set to:
=First(Fields!ImageData.Value, "dtstItemImage")
我使用以下方法设置DataSource:
And I set the DataSource using:
ImageBindingSource.DataSource = this.item.Image.ImageData;
代码编译并运行但图像未显示在报告中 。
这是因为PictureBox需要绑定到Image对象(而不是字节数组)吗?或者是否可能需要设置PictureBox的某些属性?
Is this because the PictureBox needs to be bound to an Image object (and not to a byte array)? Or are there perhaps some properties of the PictureBox which I need to set?
更新1
我为PictureBox添加了一个边框,只是为了确保它是可见的,它确实显示在报告中。它只是不包含图像。
I've added a border to the PictureBox just to make sure that's its visible and it does show up in the report. It just doesn't contain the image.
更新2
我'修复了我的代码中的错误。我改变了:
I've fixed a mistake in my code. I've changed:
ImageBindingSource.DataSource = this.item.Image.ImageData;
to:
ImageBindingSource.DataSource = this.item.Image;
因为PictureBox绑定到ImageData字段但DataSource是Image对象。
as the PictureBox is bound to the ImageData field BUT the DataSource is the Image object.
现在我得到一个小的十字图标而不是什么(至少对我而言)表示一些进展但我不知道字节[] - 位图转换代码需要在哪里。
Now I get a small cross icon instead of nothing which (at least for me) indicates some progress but I don't know where the byte[]-bitmap conversion code needs to be.
推荐答案
我设法通过设置报告的图像框来源$ c来解决这个问题$ c>属性
(以前设置为数据库
外部
)。
I managed to solve this by setting the report's Image box Source
property to Database
(it was previously set to External
).
有关不同可用源值的更多信息,请参阅(MSDN)如何:添加图像(Reporting Services)。
More info about the different available Source values can be found at (MSDN) HowTo: Add an Image (Reporting Services).
这篇关于如何在Microsoft报表中显示来自字节数组的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!