CodeVerge.Net Beta


   Explore    Item Entry    Members      Register  Login  
NEWSGROUP
.NET
Algorithms-Data Structures
Asp.Net
C Plus Plus
CSharp
Database
HTML
Javascript
Linq
Other
Regular Expressions
VB.Net
XML

Free Download:




Zone: > NEWSGROUP > Asp.Net Forum > windows_hosting.hosting_open_forum Tags:
Item Type: NewsGroup Date Entered: 6/21/2004 5:39:49 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 5 Views: 74 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
6 Items, 1 Pages 1 |< << Go >> >|
DarkoMartinovic
Asp.Net User
Embeding image in resx file6/21/2004 5:39:49 PM

0/0


Hi,

Is there anyway to embed image in resx file and use that image for rendering control.
I made my custom drop - down list with custom rendering. I'm using 14 images. I'd like to embed those images in resx file in order not to distribute them when deploying application.
Thanks in advance
Darko
shawnb
Asp.Net User
Re: Embeding image in resx file6/22/2004 5:17:40 AM

1/1


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
DarkoMartinovic
Asp.Net User
Re: Embeding image in resx file6/22/2004 12:20:33 PM

0/0


Ok, thank you. I need time to test.

Regs.D.
DarkoMartinovic
Asp.Net User
Re: Embeding image in resx file6/22/2004 1:45:27 PM

0/0

Ok, it works. I get the image, see dimension in debugger etc but unable to see in browser
image.Save(Response.OutputStream, format ) does not produce image.
Where I made a mistake?
Thanks in advance
Regs.D.


shawnb
Asp.Net User
Re: Embeding image in resx file6/22/2004 6:26:53 PM

0/0

I cooked up an example for you. You'll have to download it at:

http://www.zenofdotnet.com/downloads/Resource%20Example.zip

There are two projects: one is a web control project (that does not have webcontrols) that has the infrastructure to get the image and then there is the web project that you can examine. It works fine according to my tests. If you have any questions, let me know.

Thanks,
Shawn
Shawn B.

www.zenofdotnet.com
shawnb
Asp.Net User
Re: Embeding image in resx file8/15/2004 8:19:10 PM

0/0

I know this is a bit late but now I think I have a different understanding of what you were trying to accomplish. The example I showed above works during runtime but not design time.

There are very few examples of how to accomplish this during designtime and most solutions revolve around the control, during designtime render, getting a COM reference to the IDE and then iterating through to find the web.config and load it into an XML document, parsing it, and then reading an appSettings key for the root name.

Perter Blum has a neat little solution that does something (I don't know what) but for me to deploy my controls to other developers they would need to have it installed.

Wow. That's just too complicated for me.

IE doesn't support < img src='data:image/gif;base64,[data]' /> syntax, either, so we can't embed the image into the page. So... what can we do? You aren't going to like the answer anymore than I do.

For my Zen project, since my ZenAnchor tag uses a special image to indicate an anchor, ... I had to create a folder in my wwwroot called "designtimeimages" and everythine is referenced there like this: < img src="/designtimeimages/image.gif" /> for the IDE. At runtime, if the image is needed, it'll use the image that is stored in the resource and the images folder is never used during deployment.

I can take it a step further and borrow a trick from other peoples book and load a reference to the IDE if it is VS.NET and parse the web.config after iterating through all the project files and then if it isn't VS.NET IDE, it can fall back onto the images folder described earlier.

I think for the VS.NET 1.x you have no other choice. For 2.0, there is special support for this type of thing.


Thanks,
Shawn
Shawn B.

www.zenofdotnet.com
6 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
Windows Forms Programming in C# Authors: Chris Sells, Pages: 681, Published: 2004
Pro ASP.NET 2.0 in VB 2005: special edition. Authors: Laurence Moroney, Matthew MacDonald, Pages: 1360, Published: 2006
Visual Basic 2008 Recipes: A Problem-Solution Approach Authors: Todd Herman, Allen Jones, Matthew MacDonald, Rakesh Rajan, Pages: 680, Published: 2008
Pro VB 2005 and the .Net 2.0 Platform Authors: Andrew Troelsen, Pages: 1034, Published: 2006
Sams Teach Yourself Visual C++ .NET in 24 Hours Authors: Richard J. Simon, Mark Schmidt, Pages: 413, Published: 2002
Pro ASP.NET 2.0 in C# 2005 Authors: Matthew MacDonald, Mario Szpuszta, Pages: 1255, Published: 2005
Pro .NET 2.0 Windows Forms and Custom Controls in VB 2005 Authors: Matthew MacDonald, Pages: 1036, Published: 2006
Visual Basic 2005 Recipes: A Problem-Solution Approach Authors: Todd Herman, Allen Jones, Matthew MacDonald, Rakesh Rajan, Pages: 664, Published: 2007
Visual Basic 2005 Programmer's Reference Authors: Rod Stephens, Pages: 1022, Published: 2005
Pro .NET 2.0 Windows Forms and Custom Controls in C#: From Professional to Expert Authors: Matthew MacDonald, Pages: 1037, Published: 2005

Web:
How to use and manipulate images embedded into ASP.NET Resource ... To store image files embedded into RESX files without you need to deploy those files on ... Rendering an embedded image as it's stored in the RESX file. ...
Resources in .Resx File Format Close method to write the image information to the resource file and close ... You cannot embed a .resx file in a runtime executable or compile it into a ...
Windojitsu.com -- I Hate ResX Files Dec 23, 2004 ... You are a black hole, ResX -- woe to devs who insert images into you, ... etc) must be checked in as files, and included as embedded ...
Working with resources Using strings and embedded images directly (without localization); Creating resource files. Resources in Visual Studio .NET; Creating a .resx file for ...
How to dynamically create composite images using embedded images ... In the following guide you'll learn how to use images embedded into ASP.NET Resources Files (*.RESX) to create composite images through ImageDraw. ...
How do I properly maintain images in VS.NET? Jan 14, 2003 ... When you add any kind of a resource, like an image, to a .resx file, the data for the resource is embedded directly into the .resx file and ...
Visual Studio: How to store an image resource as an Embedded ... I want the resource to be stored as an embedded resource (my reasons are irrelevant, ... adds an image, it sets Build Action to None, because the .resx file ...
VB.NET embedding wav files into resx and resource files Hello, Does anyone know how to embedd .wav files into resource files such as in resx files the way images are embedded for instance? ...
Simple (?) question about embedding images in .NET programs ... Creating an .resx xml file. Compiling the .resx to a .resource module. Create a DLL, and embed the .resource file using the Assembly ...
Re: How to use .resx file: msg#00028 Feb 5, 2003 ... Make sure > "Images.resources" was correctly embedded or linked > into ... Previous by Thread: Re: How to use .resx file, Chris Sells ...




Search This Site:










stack and heap

new browser window

new to dotnetnuke

assigning roles using an administrator(.net 2.0)

problem with permissions

delete a module

about loginview

help desk module

host password reset?

behavior of createuserwizard

dns integration

text-edit on my container

installation issue with dnn 3.0.13

login control problem

adding "onclientclick" to treeview node...

create web site... missing from recent projects panel of start page

user control problem

image gallery

dotnetnuke module creation

install nightmare!

issue with 2.0.2 and access

sqltableprofileprovider - ado.net error resuming transaction when calling updatelastactivitydate

visual web developer installer is extremly slow

tree view kind help needed

hashing + salt passwords

removing authorization for debugging purposes

how do i install dnn 4.0 so that vwd express will recognize it?

fully working portal starter kit for asp.net 2.0

how much ram does vwd usually consume?

vs 2003 & .net v 2

 
All Times Are GMT