How to use image resource in asp.net website? How to use image resource in asp.net website? asp.net asp.net

How to use image resource in asp.net website?


you can store the url of the image in your resource file and use the following inline code in the control

<asp:Image ImageUrl="<%$resources:Image1 %>" />

Update

this link could be helpful on what you are trying to accomplish

or

you can also try to stored the resource as string and set the value to the url location instead of storing the image in the resouce file.


One thing you might try to do is to create a simple "image service" that can serve up the image in the proper format from the embedded resources.

You don't have to create web service itself, you simply create an aspx page and in the code behind you change the the Response.ContentType to be "image/png" or whatever format you prefer. This also requires a get parameter in the URL to the page itself, but that can be easily filtered. So the Page_Load method of your image service might look something like this:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load      Dim FinalBitmap As Bitmap      Dim strRenderSource As String      Dim msStream As New MemoryStream()      strRenderSource = Request.Params("ImageName").ToString()      ' Write your code here that gets the image from the app resources.      FinalBitmap = New Bitmap(Me.Resources(strRenderSource))      FinalBitmap.Save(msStream, ImageFormat.Png)      Response.Clear()      Response.ContentType = "image/png"      msStream.WriteTo(Response.OutputStream)      If Not IsNothing(FinalBitmap) Then FinalBitmap.Dispose()End Sub

Then back on your ASPX page you have...

<asp:Image ImageUrl="http://localhost/GetImage.aspx?ImageName=Image1" />

Oh, and don't forget to import System.Drawing and System.Drawing.Imaging in the page.


if you are using global resources file you need to add it like this

<img id="WelocmeICon" runat="server"  alt="welcome icon"      src="<%$resources:NmcResource,WelcomeIcon %>"  />

and because i use img control i added runatserver and id for it