?
Solved

extracting images from resx file

Posted on 2005-05-06
8
Medium Priority
?
2,398 Views
Last Modified: 2008-02-01
how can i easily extract an image from a resx file so that i view and use the image by itself.  i am working with bitmap image types.
0
Comment
Question by:WhatupE
7 Comments
 
LVL 13

Expert Comment

by:davidlars99
ID: 13948406
<%@ Page Language="VB" Debug="true" autoeventwireup="false"%>

<Script language="vb" runat="server">

example:


Sub Page_Load(ByVal s As Object, ByVal e As EventArgs) Handles MyBase.Load

      Response.Cache.SetCacheability(HttpCacheability.NoCache)
      
      Dim bmp As System.Drawing.Bitmap=New System.Drawing.Bitmap(32, 32)
      Dim rm As System.Resources.ResourceManager = New System.Resources.ResourceManager("flags", System.Reflection.Assembly.LoadFrom(Request.PhysicalApplicationPath + "\bin\flags.dll"))  '// can also be \bin\flags.resx
      
      bmp=CType(rm.GetObject(filename), System.Drawing.Bitmap)
      Response.ContentType="image/gif"
      bmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif)
      bmp.Dispose()
      
End Sub

</Script>
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 13948417
or if you have multiple files in the assemply and want to list them sequensialy then do this


1). create aspx file "mainloader.asp" and put this code in

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim bmp As Bitmap = New Bitmap(32, 32)
        Dim Resdll As System.Reflection.Assembly = System.Reflection.Assembly.LoadFile(Request.PhysicalApplicationPath + "\bin\flags.dll")
        Dim rs As System.Resources.ResourceSet
        Dim id As IDictionaryEnumerator
        Dim stream As System.IO.Stream
        Dim items() As String = Resdll.GetManifestResourceNames()
        Dim rnd As System.Random = New System.Random

        For i As Integer = 0 To items.Length - 1
            stream = Resdll.GetManifestResourceStream(items(i))
            rs = New System.Resources.ResourceSet(stream)
            id = rs.GetEnumerator()

            Dim num As Integer = -1
            While id.MoveNext()
                num += 1
                Label1.Text += String.Format("<img id='image{0}' name='image{0}' src='imageloader.aspx?filename={1}&rnd={2}' alt='{3}'>{4}{5}", num, id.Key, rnd.Next(0, 100), id.Key, "<br>", ControlChars.NewLine)
            End While
        Next
End Sub


2). create second aspx file "imageloader.aspx" and put this code in

<%@ Page Language="VB" Debug="true" autoeventwireup="false"%>

<Script language="vb" runat="server">

Sub Page_Load(ByVal s As Object, ByVal e As EventArgs) Handles MyBase.Load

      Response.Cache.SetCacheability(HttpCacheability.NoCache)
      
      Dim bmp As System.Drawing.Bitmap=New System.Drawing.Bitmap(32, 32)
      Dim rm As System.Resources.ResourceManager = New System.Resources.ResourceManager("flags", System.Reflection.Assembly.LoadFrom(Request.PhysicalApplicationPath + "\bin\flags.dll"))
      
      bmp=CType(rm.GetObject(Request.QueryString("filename")), System.Drawing.Bitmap)
      Response.ContentType="image/gif"
      bmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif)
      bmp.Dispose()
      
End Sub

</Script>


3). navigate to "mainloader.asp" to see the output
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 13

Expert Comment

by:davidlars99
ID: 13948450
0
 
LVL 11

Expert Comment

by:jatinderalagh
ID: 13957024
CheckOut this article which explains how to add resources and retrive them.

http://www.funducode.com/csharpart/csarticle19.htm
0
 

Author Comment

by:WhatupE
ID: 14072391
but is there an application out there that will allow me to view and save images residing in a resx?
0
 
LVL 8

Accepted Solution

by:
gregasm earned 1000 total points
ID: 14074620
I use this one from time to time:

http://www.codeproject.com/cs/miscctrl/resource_editor.asp

It is good, and source code is provided.
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question