【问题标题】:How can I write a folder of WPF image resources to disk?如何将 WPF 图像资源文件夹写入磁盘?
【发布时间】:2010-03-08 18:26:14
【问题描述】:

我的 WPF 应用程序“图像”中有一个文件夹,其中包含多个 .png 文件,它们的构建操作设置为资源。这些已内置到我的二进制文件中,因为我可以在 XAML 中引用它们。

我想将这些写入临时文件夹中的磁盘。我该怎么做?

我找到了几个关于嵌入式资源的答案,但不仅仅是普通资源。

【问题讨论】:

    标签: wpf resources disk


    【解决方案1】:

    回答!

     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();
         }
    
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-06
      • 1970-01-01
      相关资源
      最近更新 更多