WPF C# 读写嵌入的资源 JSON PNG JPG JPEG 图片等资源
1、嵌入资源读取
当文件属性的生成操作设置为嵌入资源时,读取方式如下:
csharp
string name = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + @"Resource\testproject\test.png";
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
System.IO.Stream stream = assembly.GetManifestResourceStream(name);
2、Resource
当文件属性的生成操作设置为资源(Resource)时,读取方式如下:
csharp
Uri uri = new Uri(@"Resource\testproject\test.png", UriKind.Relative);
StreamResourceInfo info = Application.GetResourceStream(uri);