2

I have a C# project and I use some embedded images in this project. These images are in project resources and I use them in several parts of my application. Now, I need some of these images to be beside my .exe file. And I need to do it dynamically when the program is running. So as I mentioned in the title of this question, I am going to extract files embedded in my application. A function like this:

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

That would be called like this:

Extract(WindowsFormsApplication1.Properties.Resources.PICT);

Edit: I can not use what explained in How can I extract a file from an embedded resource and save it to disk?. Because I need my resources to be private and so don't let other to take it up.

Community
  • 1
  • 1
  • 1
    possible duplicate of [How can i extract a file from an embedded resource and save it to Disk?](http://stackoverflow.com/questions/13031778/how-can-i-extract-a-file-from-an-embedded-resource-and-save-it-to-disk) and also [This](http://stackoverflow.com/questions/864140/write-file-from-assembly-resource-stream-to-disk), and you can find an answer even [Here](http://stackoverflow.com/questions/17936679/save-image-from-resource-file-to-computer-c-sharp) – Banana Aug 16 '15 at 12:09
  • @Banana: Now I tried that. Believe me, It doesn't work. – Isac Joseph Aug 16 '15 at 12:14
  • In that case please post in your question what you have tried, and why doesn't it work for you (error, exception?,etc. ) – Banana Aug 16 '15 at 12:17
  • @Banana: OK. I did it. – Isac Joseph Aug 16 '15 at 12:31
  • @Banana: And thank you for warning me ;) – Isac Joseph Aug 16 '15 at 12:31
  • i dont quite understand, you need the images to be *Beside* your `.exe` file, meaning you want to save the images to disk next to your program executable, but you dont want it to be accessible to anyone else? – Banana Aug 16 '15 at 12:41

1 Answers1

3

I guess it is not so difficult. Try this:

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