0
我有一个文件夹在我的WPF应用程序“图像”,有几个.png文件与他们的生成操作设置为资源。这些内置到我的二进制文件中,因为我可以在XAML中引用它们。如何将WPF图像资源的文件夹写入磁盘?
我想写这些到临时文件夹中的磁盘。我该怎么做呢?
我发现了一些涉及嵌入式资源的答案,但不仅仅是简单的资源。
我有一个文件夹在我的WPF应用程序“图像”,有几个.png文件与他们的生成操作设置为资源。这些内置到我的二进制文件中,因为我可以在XAML中引用它们。如何将WPF图像资源的文件夹写入磁盘?
我想写这些到临时文件夹中的磁盘。我该怎么做呢?
我发现了一些涉及嵌入式资源的答案,但不仅仅是简单的资源。
回答!
public static void ExtractFileFromResources(String filename, String location)
{
StreamResourceInfo sri = System.Windows.Application.GetResourceStream(
new Uri("pack://application:,,,/Images/" + filename));
Stream resFilestream = sri.Stream;
if (resFilestream != null)
{
BinaryReader br = new BinaryReader(resFilestream);
FileStream fs = new FileStream(location, FileMode.Create);
BinaryWriter bw = new BinaryWriter(fs);
byte[] ba = new byte[resFilestream.Length];
resFilestream.Read(ba, 0, ba.Length);
bw.Write(ba);
br.Close();
bw.Close();
resFilestream.Close();
}
}