extracting images from resx file

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.
WhatupEAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

 
davidlars99Commented:
<%@ 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
 
davidlars99Commented:
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
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
davidlars99Commented:
0
 
jatinderalaghCommented:
CheckOut this article which explains how to add resources and retrive them.

http://www.funducode.com/csharpart/csarticle19.htm
0
 
WhatupEAuthor Commented:
but is there an application out there that will allow me to view and save images residing in a resx?
0
 
gregasmCommented:
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

Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.