简体   繁体   中英

Display Image from Embedded Resource in HTML in .NET App

I create a HTML report inside a .net application, into which I want to display an image, which is going to come from a DLL where it is stored as an embedded resource.

There are situations where I might have limited access to the file system. Even still, what is the best way to get the image out of the embedded resource (I can do this programmatically into a bitmap object) and display it in the html report for the user, preferably without using the file system. The HTML is created by the app.

Some more info:

The report is created by traversing a tree of objects in code, each of which return a piece of html:

Function GetReportLine() as String
    Return String.Format("<p>Account Created on {0}</p>", CreatedTime.ToString("dd/MMM/yyyy h:mm tt"))
End Function

These are then compiled into a string, decorated with some CSS, and passed into a WebBrowser control embedded on a Form to display to the user.

I want to display an image from my embedded resource like this:

Return String.Format("<p><img src=MyEmbeddedResourceImage>Account Created on {0}</p>", CreatedTime.ToString("dd/MMM/yyyy h:mm tt"))

See this; it streams the image as a resource, not as a physical file:

http://weblogs.asp.net/jeff/archive/2005/07/18/419842.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM