How to show Image from byte array in Microsoft report

Rachel picture Rachel · Sep 7, 2012 · Viewed 11.5k times · Source

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.

The PictureBox's value is currently set to:

=First(Fields!ImageData.Value, "dtstItemImage")

And I set the DataSource using:

ImageBindingSource.DataSource = this.item.Image.ImageData;

The code compiles and runs but the image is not displayed in the report.

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?

UPDATE 1

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.

UPDATE 2

I've fixed a mistake in my code. I've changed:

ImageBindingSource.DataSource = this.item.Image.ImageData;

to:

ImageBindingSource.DataSource = this.item.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.

Answer

Rachel picture Rachel · Sep 10, 2012

I managed to solve this by setting the report's Image box Source property to Database (it was previously set to External).

More info about the different available Source values can be found at (MSDN) HowTo: Add an Image (Reporting Services).