views:

1080

answers:

1

Out of the box, in MS Reporting Services, the image element does not allow for the centering of the image itself, when the dimensions are unknown at design time. In other words, the image (if smaller than the dimensions allotted on the design surface) will be anchored to the top left corner, not in the center.

My report will know the URL of the image at runtime, and I need to be able to center this image if it is smaller than the dimensions specified in my designer.

+5  A: 

Here is how I was able to accomplish this. With help from Chris Hays

Size the image to be as big as you would want it on the report, change "Sizing" property to "Clip".

Dynamically set the image's left padding using an expression:

=CStr(Round((4.625-System.Drawing.Image.FromStream(System.Net.WebRequest.Create(Parameters!LogoURL.Value).GetResponse().GetResponseStream()).Width/96)/2,2)) & "in"

Dynamically set the image's top padding using an expression:

=CStr(Round((1.125-System.Drawing.Image.FromStream(System.Net.WebRequest.Create(Parameters!LogoURL.Value).GetResponse().GetResponseStream()).Height/96)/2,2)) & "in"

The first modification made to Chris's code was to swap out the dimensions of my image element on the report (my image was 4.625x1.125 - see numbers above).

I also chose to get the stream from a URL instead of the database. I used WebRequest.Create.GetResponse.GetResponseStream do to so.

So far so good - I Hope that helps!

Ian Robinson