2010-03-08 95 views
0

我有一個文件夾在我的WPF應用程序「圖像」,有幾個.png文件與他們的生成操作設置爲資源。這些內置到我的二進制文件中,因爲我可以在XAML中引用它們。如何將WPF圖像資源的文件夾寫入磁盤?

我想寫這些到臨時文件夾中的磁盤。我該怎麼做呢?

我發現了一些涉及嵌入式資源的答案,但不僅僅是簡單的資源。

回答

0

回答!

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

    } 
相關問題