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.
开箱即用,在MS Reporting Services中,当维度在设计时未知时,图像元素不允许图像本身居中。换句话说,图像(如果小于设计表面上分配的尺寸)将锚定在左上角,而不是中心。
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.
我的报告将在运行时知道图像的URL,如果它小于我的设计器中指定的尺寸,我需要能够将该图像居中。
1 个解决方案
#1
8
Here is how I was able to accomplish this. With help from Chris Hays
以下是我能够实现这一目标的方法。在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).
对Chris的代码进行的第一个修改是在报告中交换我的图像元素的尺寸(我的图像是4.625x1.125 - 见上面的数字)。
I also chose to get the stream from a URL instead of the database. I used WebRequest.Create.GetResponse.GetResponseStream do to so.
我还选择从URL而不是数据库获取流。我使用了WebRequest.Create.GetResponse.GetResponseStream来做到这一点。
So far so good - I Hope that helps!
到目前为止一切都很好 - 我希望有所帮助!
#1
8
Here is how I was able to accomplish this. With help from Chris Hays
以下是我能够实现这一目标的方法。在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).
对Chris的代码进行的第一个修改是在报告中交换我的图像元素的尺寸(我的图像是4.625x1.125 - 见上面的数字)。
I also chose to get the stream from a URL instead of the database. I used WebRequest.Create.GetResponse.GetResponseStream do to so.
我还选择从URL而不是数据库获取流。我使用了WebRequest.Create.GetResponse.GetResponseStream来做到这一点。
So far so good - I Hope that helps!
到目前为止一切都很好 - 我希望有所帮助!