SSRS - Accessing System.Drawing.Image.FromStream - reporting-services

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.

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

Related

How to compare two images in Robot Framework

I am new in automation and want to automate a site whose back-end in HTML5 and containing canvas element.
I want to compare canvas images with my stored image.
For image comparison I need to use robot framework.
I had tried with "robotframework-imagehorizonlibrary" library but still testcases were failed.
Can any one please help me.
Thanks.
I would suggest the RobotAppEyes Library, which is basically an extended version of Selenium2 library, and it actually has a keyword named Compare Images.
Use it as the following:
Compare Image <path, imagename=None, ignore_mismatch=False, includeEyesLog=False, httpDebugLog=False>
see details here: http://navinet.github.io/Robot-AppEyes/RobotAppEyes-KeywordDocumentation.html

Gmod Lua Coding - How to place an HTML5 Page (Website) Inside of a Box

I've been working with a friend and we both have a problem, in a Garry's Mod Server, ok so we have a box saying Rules, and when we go to place a website INSIDE OF THAT BOX, it shows exactly this:
http://cloud-4.steamusercontent.com/ugc/37489242708029141/B4E51CC2F089F13DF25AA8F4F3E9BF7A07619427/
As you can see, it shows a box with the HTML5 coding, not sure if I can place:
http://www.sparkperp.com/Rules/index.html on that box.
I would like to know how to do that, if it's possible.
Thanks for your help
Please give your code in the future. Since I'm unable to view your code I'm limited in how much I can help, but I will try my best anyway!
You need to use the HTML vgui element vgui.Create("HTML") and use :OpenURL(weblink) on it. You can also use :SetHTML(htmlstring) if required. You should get the idea from the below code block:
local MOTD = vgui.Create( "HTML", parent )
MOTD:OpenURL("http://www.sparkperp.com/Rules/index.html")
If you can't get it working, update your question with your code and I'll be able to help further.

Creating custom SSRS handler for field with HTML

I have an SSRS 2008 report with a field that contains and is configured to render as HTML. Some of the text in this field may contain IMG tags, and the IMG tag is not among the tags SSRS natively supports within its HTML rendering extension.
I am trying to find a way to write a custom handler to hook into the processing of this field that will let me look at the raw HTML before the SSRS handler processes it, in the hopes of grabbing IMG tags, extracting the SRC URL and getting the raw bytes of an image to insert on the fly in a way SSRS will accept, yet retaining the HTML SSRS will render.
From what I've read and seen so far, if a field is marked to render as HTML, the SSRS processor grabs it and parses it entirely before any handler could modify it, meaning the IMG tag is (would be) discarded before I could do anything with it (or even know it was present). The only option I see is to turn off the HTML rendering entirely, thus losing the benefit of the tags SSRS can recognize.
EDIT: Per Jamie's response below, I'm beginning to think the "2nd half" of this issue may prove harder than I realized: Is it even possible to programmatically add an Image to an SSRS Report at runtime (obviously through code/custom assembly)? That is, I'd like to write some code that might look something like this (pseudocode)
'Conceptual Pseudocode I'd like to be able to write
'for dynamic addition of Image element in SSRS report
'Is this even possible?? Is there a documented Report
'object model??
Public Function AddImage(imageBytes() as Byte) as Image
Dim newImage as New Image()
newImage.SetBytes(imageBytes)
Report.Add(newImage)
return newImage
End Function
I'm hoping I'm just overlooking something simple that prevents me from grabbing the raw, unprocessed HTML, and someone else might be able to point me in the right direction on how to grab it.
EDIT: I have created and implemented this solution within the SSRS development environment and it works. WOOHOO :) It did require some hoop-jumping with creating a Single-Threaded Apartment thread to host the WebBrowser control, and to create a message pump, but it does work! **
As I was literally typing up the message to a co-worker that this issue was a non-starter, I did have a bit of an inspiration on a way to solve this problem. I know this post hasn't generated a great deal of response, but just in case someone else finds themselves in a similar problem, I'm going to share what I've implemented in a "petri dish" scenario that, provided I get all the code permission issues resolved, should allow me a decent solution to this problem.
With SSRS inability to handle an IMG tag insurmountable, I actually thought of an idea that took the HTML rendering away from SSRS entirely. To do this, I created custom code that hands off the HTML rendering to a WebBrowser control, then copies the rendered result as an image. It does the following:
Instantiates a WebBrowser control of a given width and height.
Sets the DocumentText property of that control to the HTML from TinyMCE
Waits for the DocumentText to completely render.
Creates a bitmap equal to the size of the control.
Uses the undocumented and presumably unsupported DrawToBitmap method of the WebBrowser to draw the rendered HTML to a bitmap.
Copies the Bitmap to an Image
Saves the Image as a .png file
Returns the path to the .png as the result of the function.
In SSRS, I plan to replace the erstwhile HTML text field with an external Image control that will then call the above method and render the image file. I may alter that to simply draw the image to the SSRS Image control directly, but that's a final detail I'll resolve later. I think this basic design is going to work. Its a little kludgey, but I think it will work.
I have some permissions issues to work out with the code that SSRS will allow me to call at runtime, but I'm confident I'll get those sorted out (even if I end up moving the code to a separate assembly). Once this is tested and working, I plan to mark this as the answer.
Thanks to those who offered suggestions.
I've done something similar with success: We had an HTML "Comment" field that was collected on a web form. For a particular report we wanted to truncate this field to the first 1000 characters or so, but preserve valid HTML.
So I created a C# .dll & class with a public function:
public static string TruncateHtml(string html, int characters)
{
...
}
(I used the HtmlAgilityPack for most of the HTML parsing, and to create and close off my new HTML string, while I kept track of the content length.)
Then I could call that code with the fully qualified path to the function in an SSRS expression:
=ReportHtmlHandler.HtmlTruncate.TruncateHtml(Fields!Comment.Value, 1000)
I could have added a calculated field to my dataset with this, but I was only using this value for one field, so I kept it at the field expression level.
All of this code gets called well before the HTML is processed or rendered by SSRS. I'm sure that any original IMG tag will be in the string.
This approach might work for you, possibly create a ExtractImg function which could be set as the source of an img on the report. I think some of the tricky bits for your requirement will be to handle multiple images as well as embedding the extracted img. But you might be able to do this simply with a external reference to an image. I haven't done much with external images in SSRS.
An MSDN blog entry on calling a custom dll from SSRS: http://support.microsoft.com/kb/920769

URL Masking in .Net / HTML

I have a website in which I have many categories, many sub-categories within each one and many products within each of those. Since the URLs are very user-unfriendly (they contain a GUID!!!), I would like to use a method which I think is called URL Masking. For example instead of going to catalogue.aspx?ItemID=12343435323434243534, they would go to notpads.htm. This would display the same as going to catalogue.aspx?ItemID=12343435323434243534 would display, somehow.
I know I could do this by creating a file for each category / sub-category (individual products cannot be accessed individually as it is a wholesale site - customers cannot purchase directly from the site). This would be a lot of work as the server would have to update each relevant file whenever a category / sub-category / product visibility changes, or a description changes, a name changes... you get the idea...
I have tried using server-side includes but that doesn't like it when a .aspx file is specified in an html file.
I have also tried using an iframe set to 100% width / height and absolutely positioned left 0 and top 0. This works quite well, but I know there are reasons you should not use this method such as some search engines not coping with it well. I also notice that the title of the "parent" page (notepads.htm) is not the title set in the iframe (logically this is correct - but another issue I need to solve if I go ahead and use this method).
Can anyone suggest another way I could do this, or tell me whether I am going along the right lines by using iframes? Thanks.
Regards,
Richard
PS If this is the wrong name for what I am trying to do then please let me know what it actually is so I can rename / retag it.
Look into URL Rewrites. You can create a regular expression and map it to your true url. For example
http://mysite.com?product=banana
could map to
http://mysite.com?guid=lakjdsflkajkfj3lj3l4923892&asfd=9234983920894893
I believe you mean URL Rewriting.
IIS 7+ has a rewrite module built in that you can use for this kind of thing.
URL Rewriters solve the problem you are describing - When someone requests page A, display page B - in a general way.
But yours is not a general requirement. You seem to have a finite uuid-to-shortname mapping requirement. This is the kind of thing you could or should set up in your app, yourself, rather than inserting a new piece of machinery into your system.
Within a default .aspx page, You'd simply do a lookup on the shortname from the url in a persistent table stored somewhere, and then call Server.Transfer() to the uuid-named page associated to that shortname.
It should be easy to prototype this.

Is there a way to get ms-access to display images from external files

I've got an MS-Access app (1/10th MS-Acccess, 9/10ths MS-SQL) that needs to display photographs of some assets along with their specifications. Currently the images are stored in an MS-Access table as an OLE Object (and copy-n-pasted into the field by the users).
For various reasons, I would like to do is store the original .jpgs in a folder on the network drive, and reference them from the application portion. I have considered moving into MS-SQL's image data type (and its replacement varbinary), but I think my user population will more easily grasp the concept of the network folder.
How can I get MS Access to display the contents of a .jpg?
Another option is to put an image control on your form. There is a property of that control (Picture) that is simply the path to the image. Here is a short example in VBA of how you might use it.
txtPhoto would be a text box bound to the database field with the path to the image
imgPicture is the image control
The example is a click event for a button that would advance to the next record.
Private Sub cmdNextClick()
DoCmd.GoToRecord , , acNext
txtPhoto.SetFocus
imgPicture.Picture = txtPhoto.Text
Exit Sub
End Sub
Have you looked at Stephen Lebans' solutions? Here's one:
Image Class Module for Access
Check out the list of other great code along the left-hand side of that web page. You may find something that fully matches what you need.
I found that this article by Microsoft with full VBA worked very well for me.
How to display images from a folder in a form, a report, or a data access page
The easiest way is probably to plop an Internet Explorer onto one of your forms. Check out this site: http://www.acky.net/tutorials/vb/wbrowser/
Since you can reference that object in Access, you will only need to point the webbrowser control to the path of the .jpg (NavigateTo() if I remember correctly).
EDIT: The above link was just googled and picked from the results (first one that opened quickly). I do not think it is a very good tutorial, it just has all the pointers you need... Check out msdn etc. if you need more information!
You can try an ActiveX control called AccessImagine, makes adding images to database more convenient - you can load from file, scan, paste from buffer or drag-n-drop. You can crop image right inside the database and resample it automatically. It handles external image storage automatically if you need it.
Note that in Access 2010 (and later) this is dead simple to do because the Image control can be bound to a field in the table that contains the path to the image file (.jpg, .png, ...). No VBA required.
For more details see my other answer here.
Do you mean something like this?
Display images in MS-Access Form tabular view.
Here's the original post from microsoft:
https://learn.microsoft.com/en-us/office/troubleshoot/access/display-images-using-custom-function
You just need to modify something in the form events:
Modify this part of the form code
Image Control
Name: ImageFrame
Picture: "C:\Windows\Zapotec.bmp"
Control Source: txtImageName
Note that the Control Source named "txtImageName" is the field name in your table which has the name and path of your images.
Everything get's fine after you modify that part.