2015-08-16 141 views
2

我有一個C#項目,我在這個項目中使用了一些嵌入式圖像。這些圖像在項目資源中,我在我的應用程序的幾個部分中使用它們。現在,我需要將這些圖像放在我的.exe file旁邊。我需要在程序運行時動態地執行它。正如我在這個問題的標題中提到的,我將提取嵌入在我的應用程序中的文件。像這樣的功能:如何從資源中提取圖像?

public static void Extract(Bitmap imageToExtract, string destination); 

那被稱爲是這樣的:

Extract(WindowsFormsApplication1.Properties.Resources.PICT); 

編輯:我不能用什麼How can I extract a file from an embedded resource and save it to disk?解釋。因爲我需要我的資源是私人的,所以不要讓其他人接受它。

+1

可能重複[我如何從嵌入式資源提取文件並將其保存到磁盤?](http://stackoverflow.com/questions/13031778/how-can-i-extract -a-file-from-an-an-embedded-resource-and-save-it-to-disk)以及[This](http://stackoverflow.com/questions/864140/write-file-from-assembly-resource - 流到磁盤),並且你甚至可以找到一個答案[Here](http://stackoverflow.com/questions/17936679/save-image-from-resource-file-to-computer-c-sharp) – Banana

+0

@Banana:現在我嘗試了。相信我,它不起作用。 –

+0

在這種情況下,請發表你的問題,你已經嘗試了什麼,爲什麼不爲你工作 – Banana

回答

3

我想這不是那麼難。試試這個:

public static void Extract(Bitmap imageToExtract, string destination) { 
    System.IO.File.WriteAllBytes(
     destination, 
     ImageToByte(
      imageToExtract 
     ) 
    ); 
}