相关文章推荐
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am currently trying to center an image on screen in SSRS. While this functionality is not directly support it is possible to provide custom padding based on the image size. This is an external image provided by a database, so the image changes repeatedly and I cannot hard code a padding. I am trying to retrieve the width of the image using:

=System.Drawing.Image.FromStream(new System.IO.MemoryStream(CType(System.Convert.FromBase64String(Fields!HomeLogoImage.Value), Byte()))).Width

However when this is entered into an expression place holder, "FromStream" is not recognised.

I can confirm that I have added the reference to the system.drawing assembly and I am using version 4.0.0.0.

I am returning to SSRS for the first time in quite a while so any advice on this would be greatfully received. Or even if there is a way to center images without resorting to the System.Drawing method, I would love to hear.

Many thanks.

Just ignore the highlighting. The expression syntax checking is pretty poor. Try changing System.Drawing.Image.FromStream to System.Drawing.Dave.FromStream and you'll see that FromStream is still highlighted. – Alan Schofield Jan 25, 2022 at 12:51 @AlanSchofield thanks for the advice. Intelisense is usually anything but inteligent. Do you have any idea on the correct format for this call or what the underlying cause actually is? – Matthew Baker Jan 25, 2022 at 13:54 It's been a while since I used images in SSRS but I managed to cobble something togther, answer added. You didn;t actually say what error you got so if this does not help, include this please. – Alan Schofield Jan 25, 2022 at 15:26

Try the following. I've tested this against some .png database images I had lying around and it seemed to work.

=System.Drawing.Image.FromStream
                    (new System.IO.MemoryStream(CType(Fields!Image.Value,Byte())))
                    .Width

EDIT after OP update

To do the same with an external image you can use the following

=System.Drawing.Image.FromStream
                    (new System.IO.FileStream(Fields!HomeLogoImage.Value, IO.FileMode.Open))
                    .Width

This assumes that the HomeLogoImage field contains a valid path and filename to the image.

However You will probably encounter a permissions error. I have not done this myself so I can only point you to a link that discusses the issue with possible solutions. I've not done anything other than a quick search to find this so better solutions may be available

https://social.msdn.microsoft.com/Forums/sqlserver/en-US/31490332-c2f7-48a4-9928-29916ce002b4/request-for-the-permission-of-type-systemsecuritypermissionssecuritypermission-mscorlib?forum=sqlreportingservices

Hi @Alan I believe I know what is happening here. I am using external images, i.e. the field in the dataset is a location on the server i.e. "c:\images\myImage.png" rather than a blob of data. I thought (incorrectly) that this was being handled by the "System.Convert.FromBase64String" but obviously not. – Matthew Baker Jan 26, 2022 at 9:00 Error when running my code was "[rsRuntimeErrorInExpression] The Value expression for the textrun 'HomeTitle.Paragraphs[2].TextRuns[0]' contains an error: The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters." – Matthew Baker Jan 26, 2022 at 9:00 Error when running your code "[rsRuntimeErrorInExpression] The Value expression for the textrun 'HomeTitle.Paragraphs[2].TextRuns[0]' contains an error: Unable to cast object of type 'System.String' to type 'System.Byte[]'." – Matthew Baker Jan 26, 2022 at 9:02 I've got some old reports somewhere that use external images in the same way, I will try to dig them out and test with those later today. – Alan Schofield Jan 26, 2022 at 10:41 Hi Alan. Marked as correct answer, has taken a while to get there but this set me on the right track. Still having some permission issues, but I'll raise as a seperate question. Many thanks for the help. – Matthew Baker Feb 8, 2022 at 10:22

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.

 
推荐文章