2

I want to add/update Image resources in a .NET project, so that when the application is compiled the images will be available at runtime.

Due to having a large amount of images in several locations I want to do this using a separate vb.net project.

The only way I can see to do this is to copy the image file to the [Project]\Resources folder and then edit the [Project]\My Project\Resources.resx to use this image file, but this seems a bit hacky and I'm not sure how fussy Visual Studio is about the format of the resx file.

Is there some other way of doing this?

Matt Wilko
  • 26,994
  • 10
  • 93
  • 143

2 Answers2

2

Here you go :) Looking at your tags, there's no need for many words

Short sweet and down to the point paint explanation

enter image description here

Riaan Walters
  • 2,587
  • 2
  • 18
  • 30
  • Thanks - I was looking for a way to do this programmatically though! – Matt Wilko Nov 09 '12 at 09:11
  • ill go dig around, although I am not sure if this can be done from the application you want to change, since you EXE will be locked because your using it. Ill do some testing 1 moment – Riaan Walters Nov 09 '12 at 09:15
  • [Check this post](http://stackoverflow.com/questions/9349784/updating-images-in-resource-section-of-an-exe-in-c-c#9446836) Roughly the same question - If that answers your question, why dont you finish close this question by marking this answer :) – Riaan Walters Nov 09 '12 at 09:18
1

You can use the ResourceWriter class to programmatically create a binary resource (.resources) file directly from code.

    using (ResourceWriter rw = new ResourceWriter(@".\CarResources.resources"))
    {
       Image im = Image.FromFile("C:\\sample.jpg");
        rw .AddResource("sample.jpg", im) 
      }

You can also use Resource File Generator (Resgen.exe) to create a .resources file from a text file or a .resx file.

indiPy
  • 7,844
  • 3
  • 28
  • 39
  • I saw this, but can you edit a resource this way as well? (just for my own knowledge) :) - The OP's title and Question signify different things aswell. – Riaan Walters Nov 09 '12 at 09:29
  • @Rikoshay - apologies I have edited the title to hopefully be clearer – Matt Wilko Nov 09 '12 at 09:35
  • yes you can .. http://stackoverflow.com/questions/676312/modifying-resx-file-in-c-sharp or you need to open file in write mode and edit. – indiPy Nov 09 '12 at 09:39
  • 1
    Very interesting, I'll keep this in mind, hope the OP see's this – Riaan Walters Nov 09 '12 at 09:43
  • @MattWilko edited my answer with way to add image runtime.. also, there are lot of overload accepted by addResources method. – indiPy Nov 09 '12 at 09:45