WPF中Resx文件中添加Byte[]

参考:https://learn.microsoft.com/zh-tw/dotnet/api/system.resources.resxresourcewriter.generate?view=windowsdesktop-8.0&viewFallbackFrom=netcore-3.1
代码实现:

static void Main(string[] args)
{
            using(ResXResourceWriter resWriter=new ResXResourceWriter(@"F:\xxxx\xxx\MyResource.resx"))
            {
                byte[] secBytes = File.ReadAllBytes(@"F:\xxx\MyResources\rhlsl.xxx");
                resWriter.AddResource("rhsl", secBytes);
                resWriter.Generate();
            }
            Console.Write("xxx");
}

然后再打开MyResource.resx

那么,现在可以直接用MyResources.rhsl来得到byte[],(前提是有MyResource.Designer.cs)
从而

MemoryStream stream = new MemoryStream(Resources.rhsl);
StreamReader sr = new StreamReader(stream, Encoding.UTF8);
string result= sr.ReadToEnd();

就可以得到result。

posted @ 2024-10-14 23:17  JohnYang819  阅读(8)  评论(0编辑  收藏  举报