gpt4 book ai didi

asp.net - 图像作为 Asp.Net 5 类库中的资源

转载 作者:行者123 更新时间:2023-12-04 17:33:46 25 4
gpt4 key购买 nike

在 .net 4.5 中,我能够向我的项目添加资源文件,将图像作为位图添加到该资源文件并通过 Properties.Resources.ImageName 访问它们。我如何在 4.6 dnx 中编译图像?

提前致谢!

最佳答案

您可以在 project.json 的“资源”部分下指定将被编译到程序集中的文件,如下所示:

"resources": [
"path/to/yourfile.png"
],

之后,假设您的项目名称是 YourProject,则可以通过以下方式访问该文件:
const string path = "YourProject.path.to.yourfile.png";
Assembly.GetExecutingAssembly().GetManifestResourceStream(path)

请注意文件系统路径中的斜杠如何转换为资源路径中的句点。

注意:在 1.0.0-rc1(可能还有 -beta8,尚未检查)中,项目设置从 resources 重命名至 resource

关于asp.net - 图像作为 Asp.Net 5 类库中的资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31972571/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com