Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Accessing objects in resource files

Accessing objects in resource files

Scheduled Pinned Locked Moved C#
questionlearning
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rendili
    wrote on last edited by
    #1

    How do you access jpgs bitmaps and icons in a resource file?

    T 1 Reply Last reply
    0
    • R Rendili

      How do you access jpgs bitmaps and icons in a resource file?

      T Offline
      T Offline
      turbochimp
      wrote on last edited by
      #2

      I have a previous post here[^] that might help. Enjoy.

      The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’

      R 1 Reply Last reply
      0
      • T turbochimp

        I have a previous post here[^] that might help. Enjoy.

        The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’

        R Offline
        R Offline
        Rendili
        wrote on last edited by
        #3

        Thank you very much for your help. I have tried your code, it compiles but I get the error "Stream is not a valid resource file" I created a MyResources.RES file using RC.exe and compiled the app with the following command line : csc /debug- /t:winexe /win32res:MyResources.RES /w:4 /o+ *.cs It seems to embed the resources in the exe as it much larger than if i do not have the /win3res switch any idea why it won't work?

        T 1 Reply Last reply
        0
        • R Rendili

          Thank you very much for your help. I have tried your code, it compiles but I get the error "Stream is not a valid resource file" I created a MyResources.RES file using RC.exe and compiled the app with the following command line : csc /debug- /t:winexe /win32res:MyResources.RES /w:4 /o+ *.cs It seems to embed the resources in the exe as it much larger than if i do not have the /win3res switch any idea why it won't work?

          T Offline
          T Offline
          turbochimp
          wrote on last edited by
          #4

          Assuming you're not creating the resource you're consuming (if you were, I would suggest saving a lot of hassle and just using the ResourceWriter type), and you're stuck with a Win32 resource, you should be able to use the ResourceManager type to get what you need if, as your example suggests, you're embedding the resource in your application assembly. Example (where the byte array is your serialized image stream):

          public byte[] Binary(string key)
          {
              ResourceManager resManager = new ResourceManager("[ASSEMBLYNAME]", This.GetType().Assembly);
                return (byte[]) resManager.GetObject(key);
             }
          

          Here[^] is a link with a little more info. Hope this helps.

          The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’

          R 1 Reply Last reply
          0
          • T turbochimp

            Assuming you're not creating the resource you're consuming (if you were, I would suggest saving a lot of hassle and just using the ResourceWriter type), and you're stuck with a Win32 resource, you should be able to use the ResourceManager type to get what you need if, as your example suggests, you're embedding the resource in your application assembly. Example (where the byte array is your serialized image stream):

            public byte[] Binary(string key)
            {
                ResourceManager resManager = new ResourceManager("[ASSEMBLYNAME]", This.GetType().Assembly);
                  return (byte[]) resManager.GetObject(key);
               }
            

            Here[^] is a link with a little more info. Hope this helps.

            The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’

            R Offline
            R Offline
            Rendili
            wrote on last edited by
            #5

            Using win32 resources looks very complicated (looked your url) Maybe I am going about it all the wrong way. What is the best way to use icons and jpgs/bmps in a c# application? Would I need to have seperate files to keep with the exe or can they be embedded into the exe? At the moment I have 6 BMPs that I use in an image list for use on a listview, and at the moment I have the exe and the 6 BMP files in the same folder so i can access them. I also would like to add an icon the exe and the status bar and stop using the default one. Would I need to have seperate file(s) to the exe to allow this? Thanks again for your help

            T 1 Reply Last reply
            0
            • R Rendili

              Using win32 resources looks very complicated (looked your url) Maybe I am going about it all the wrong way. What is the best way to use icons and jpgs/bmps in a c# application? Would I need to have seperate files to keep with the exe or can they be embedded into the exe? At the moment I have 6 BMPs that I use in an image list for use on a listview, and at the moment I have the exe and the 6 BMP files in the same folder so i can access them. I also would like to add an icon the exe and the status bar and stop using the default one. Would I need to have seperate file(s) to the exe to allow this? Thanks again for your help

              T Offline
              T Offline
              turbochimp
              wrote on last edited by
              #6

              Using Win32 resources is not particularly complicated in general, but the .Net Framework does not have stellar legacy support built in. See the link in my initial post, using ResourceWriter and ResourceReader. It should do exactly what you're suggesting, and provides examples for how to read from and write to .resources files. You can put more than one resource in a .resources file; they are added in key/value pairs. Good luck.

              The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’

              R 1 Reply Last reply
              0
              • T turbochimp

                Using Win32 resources is not particularly complicated in general, but the .Net Framework does not have stellar legacy support built in. See the link in my initial post, using ResourceWriter and ResourceReader. It should do exactly what you're suggesting, and provides examples for how to read from and write to .resources files. You can put more than one resource in a .resources file; they are added in key/value pairs. Good luck.

                The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’

                R Offline
                R Offline
                Rendili
                wrote on last edited by
                #7

                OK thanks for all your help I will try getting this working using your original post

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups