Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show Image from byte array in Microsoft report

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.

like image 531
Rachel Avatar asked Sep 07 '12 13:09

Rachel


People also ask

How do I display an image in a byte array?

To convert a byte array to an image. Create a ByteArrayInputStream object by passing the byte array (that is to be converted) to its constructor. Read the image using the read() method of the ImageIO class (by passing the ByteArrayInputStream objects to it as a parameter).


1 Answers

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

like image 157
Rachel Avatar answered Oct 07 '22 21:10

Rachel