问题
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?
回答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.
回答2:
Here you go :) Looking at your tags, there's no need for many words
Short sweet and down to the point paint explanation
来源:https://stackoverflow.com/questions/13304892/add-image-file-resource-to-another-project