本文介绍了图像在Asp.Net 5类资源库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在.NET 4.5我能为位图由Properties.Resources.ImageName资源文件添加到我的项目,将图像添加到这个资源文件并访问它们。如何在4.6 DNX图像编译?

In .net 4.5 i was able to add a resource file to my project, add images as bitmaps to this resource file and access them by Properties.Resources.ImageName. How do i compile images in 4.6 dnx?

在此先感谢!

推荐答案

您可以指定将在project.json的资源部分被编译成汇编,像这样的文件:

You can specify the files that will be compiled into the assembly under the "resources" section in project.json, like so:

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

之后,假设你的项目的名字YourProject,该文件可以通过访问:

After which, assuming your project's name is YourProject, the file can be accessed via:

const string path = "YourProject.path.to.yourfile.png";
Assembly.GetExecutingAssembly().GetManifestResourceStream(path)

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

Note how the slashes in the filesystem path are converted into periods in the resource path.

请注意:在1.0.0-RC1(也可能是-beta8,还没有检查)项目设置从资源改名资源

Note: In 1.0.0-rc1 (and possibly -beta8, haven't checked) the project setting is renamed from resources to resource

这篇关于图像在Asp.Net 5类资源库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 03:33