Add Image file resource to another project

微笑、不失礼 提交于 2019-12-11 01:42:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!