简体   繁体   English

从vb.net中“资源”的子目录获取文件

[英]Getting files from a sub-directory of Resources in vb.net

I'm making a map creator that chooses images randomly from various sets. 我正在制作一个地图创建者,它从各种集合中随机选择图像。 What I'm trying to do is set up subfolders in Resources and put the different images in each folder - eg, a folder for streets, a folder for monuments, etc. Then I just make an array of images out of the files in the folder, and pick one. 我想做的是在参考资料中设置子文件夹,然后将不同的图像放在每个文件夹中,例如,用于街道的文件夹,用于纪念物的文件夹等。然后,我仅根据文件中的文件制作图像数组文件夹,然后选择一个。

For some reason, I can't find a simple way of getting at the subfolders. 由于某种原因,我找不到找到子文件夹的简单方法。 I've tried using IO.Path.GetFullPath(My.Resources.ResourceManager.BaseName) and appending the folder name to the end of it, but no luck. 我尝试使用IO.Path.GetFullPath(My.Resources.ResourceManager.BaseName)并将文件夹名称附加到它的末尾,但是没有运气。

Is there some other way of getting the path? 还有其他途径吗? Is it even possible to use subfolders of Resources? 甚至可以使用资源的子文件夹吗? Is there a better way of doing what I'm trying to accomplish? 有没有更好的方法来完成我要完成的工作? I'd really like to avoid creating the image arrays by hand. 我真的很想避免手动创建图像数组。

It is quite unclear to me how you created subfolders for Resources. 对我来说,目前还不清楚您是如何创建“资源”子文件夹的。 Which is probably the source of your problem. 这可能是您问题的根源。 My.Resources refers to resources that you add in the Project + Properties, Resources tab. My.Resources是指您在“项目+属性”的“资源”选项卡中添加的资源。 Those resources get embedded into your program, they become part of the assembly itself. 这些资源被嵌入到您的程序中,它们成为程序集本身的一部分。 You can't get a path for it such a resource, it isn't a file. 您无法获得此类资源的路径,它不是文件。 You have to use My.Resources.ResourceManager to retrieve them, it uses Assembly.GetmanifestResourceStream() internally to get to the embedded data inside the assembly. 您必须使用My.Resources.ResourceManager来检索它们,它在内部使用Assembly.GetmanifestResourceStream()来获取程序集中的嵌入式数据。

Not sure where you want to go with this, but if you actually want to use files in a folder instead of an embedded resource then you should not use My.Resources. 不知道在哪里,你想要去的,但如果你真正想要的文件夹中使用的文件,而不是嵌入的资源,那么你应该使用My.Resources。 Doing this is a bit of a hassle because you have to copy the files from your project directory to the bin\\Debug and bin\\Release directory. 这样做有点麻烦,因为您必须将文件从项目目录复制到bin \\ Debug和bin \\ Release目录。 Using My.Resources is usually the preferred solution, especially since the user doesn't get ready access to your art, but it doesn't let you organize the resources into folders. 通常,首选My.Resources解决方案,尤其是因为用户无法随时访问您的作品,但它不允许您将资源组织到文件夹中。 Let us know what you really want to do. 让我们知道您真正想要做什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM