2

Currently I'm loading the image from the local disk but I would like to embed the image into the program, I have added the image epsonScanner.png to the project and it appears in Solution Explorer how can add this to the array?

images.Add(Image.FromFile(@"E:\epsonScanner.png")); 
Steve Wood
  • 51
  • 1
  • 1
  • 4
  • The question is very vague, and saying that you added it to the "Solution explorer" isn't really something correct. Solution explorer is just a tool of Visual Studio. You added the image, perhaps, to a project? Or as a solution item? Then what are you exactly trying to accomplish? You want to make a collection of image objects? Also format your code using the apposite syntax. Please review your question, elaborate it and format it. – Matteo Mosca Dec 14 '11 at 10:32
  • Sorry, yes I have added the image to the project and it appears in solution explorer. I just want to pre-load the first image, the users will add other images. Thanks. – Steve Wood Dec 14 '11 at 10:35
  • Adding the file through code is different from adding it through VS. You might have to add the image into a byte[] array depending on what you want but as Matteo Mosca said, we need more details – Bali C Dec 14 '11 at 10:35
  • Maybe [this answer][1] from me can give you a little guidance. [1]: http://stackoverflow.com/questions/4860996/c-sharp-place-resource-files-to-separate-folder/4861623#4861623 – Oliver Dec 14 '11 at 10:44

3 Answers3

4

you should add the image file (epsonScanner.png) to the c# project not just as solution item. after you added, right click on it and set compile as Embedded Resource in the properties window.

after that you retrieve the image from the assembly resources and not by file path, check here for full example on how to do it:

Load image from resources area of project in C#

Community
  • 1
  • 1
Davide Piras
  • 43,984
  • 10
  • 98
  • 147
0

You can do it in the way you described and answer is already there, but i think it may be easier and cleaner to add Resource item to your project and place images there.

How to create and use resources in .NET

http://msdn.microsoft.com/en-us/library/7k989cfy%28v=vs.80%29.aspx

Community
  • 1
  • 1
wiero
  • 2,176
  • 1
  • 19
  • 28
0

You can use Bitmap.FromFile(string fileName) method.

try This.

List<Image> imageList = new List<Image>(); 
imageList.Add(Bitmap.FromFile(YourFilePath));
Sampath
  • 1,173
  • 18
  • 29