2010-03-08 4 views
0

Build Action이 Resource로 설정된 .png 파일이 여러 개있는 WPF 앱 "이미지"에 폴더가 있습니다. 이들은 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(); 
    } 

    } 
관련 문제