This took a while (2 hours) but I think I got it. Bare with me, I have created a major rewrite of the ASP.NET framework and have included it in the ability to reference files that don't exist and because of this post I added the ability to reference images from a resource file. Now, I'm going to try and seperate the necessary logic for you to answer your question and I'm not actually testing this but it most certainly works in my framework... I think you'll get the point. I will be pasting much of the code but removing references to things you won't have...
Create a new WebForm in your web site called "virtual_link.aspx" and remove all markup from it. It should only have the page directives.
Next, add the following code [VB Alert]:
Private Sub Page_Load...
Dim format As ImageFormat
Dim image As System.Drawing.Bitmap
Dim util As New Utility.Resources
Dim key As String
If (Request.QueryString("ir") <> "") Then
key = Request.QueryString("ir")
Select Case (LCase(Request.QueryString("t")))
Case "bmp"
format = ImageFormat.Bmp
type = ZenVirtualLinkType.Bmp
Response.ContentType = "image/bmp"
Case "gif"
format = ImageFormat.Gif
type = ZenVirtualLinkType.Gif
Response.ContentType = "image/gif"
Case "jpg", "jpeg"
format = ImageFormat.Jpeg
type = ZenVirtualLinkType.Jpeg
Response.ContentType = "image/jpeg"
Case "png"
format = ImageFormat.Png
type = ZenVirtualLinkType.Png
Response.ContentType = "image/png"
Case Else
GoTo Xit
End Select
' Look for an image name ("ir" := Image Resource)
'
image = CType(GetVirtualLinkResourceImage(key, type), Drawing.Bitmap)
image.Save(Response.OutputStream, format)
End If
Xit:
Response.End()
End Sub
Public Function GetVirtualLinkResourceImage( _
ByVal key As String, _
ByVal type As ZenVirtualLinkType _
) As Object
Dim image As Object
Dim util As Utility.Resources
Select Case type
Case ZenVirtualLinkType.Bmp
Case ZenVirtualLinkType.Gif
Case ZenVirtualLinkType.Jpeg
Case ZenVirtualLinkType.Png
Case Else
Return Nothing
End Select
util = New Utility.Resources
image = util.GetImage(key)
Return image
End Function
Public Enum ZenVirtualLinkType
Bmp
ECMAScript
Gif
Javascript
Jpeg
JScript
Png
VBScript
XML
CSS
End Enum
Add a the following utility class:
Imports System.Reflection
Imports System.Resources
Namespace Utility
Friend Class Resources
Public Function GetStringValue(ByVal name As String) As String
Dim res As New ResourceManager("Zen.Web.Strings", Me.GetType.Assembly)
Return res.GetString(name)
End Function
Public Function GetImage(ByVal name As String) As Object
Dim res As New ResourceManager("Zen.Web.Images", Me.GetType.Assembly)
Return res.GetObject(name)
End Function
End Class
End Namespace
Now, go find the "ResEdit" program in the "program files/microsoft visual studio.net 2003/sdk/samples/tutorials" folder and compile it. When you do so, add a jpeg image to the resource and save it as "Images.resx" in your web application directory and then include it into your project (or simply open the one you already have and add the image to that resource file instead). You'll have to change my "Zen.Web.Images" namespace to your own first (the format is "my.root.namespace.resroucename". When you pass in the name, you are passing the name of the image that you give it in the ResEdit program and that is how it'll be referenced.
Well, this should be the easy part. Next... go into your aspx page that you will preview the image...
...
<img src="virtual_link.aspx?ir=myimageresourcename&t=jpeg" />
...
That should do it. As I said, I didn't test the code in this post (I will if it doesn't work for you) but it works in my framework quite well.
Thanks,
Shawn
Shawn B.
www.zenofdotnet.com