Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: WinForm
Hello Everyone,
 
I have two problems with my Winforms application.
 
In my app im reading from a folder that contains 1000 photos.
 
1. Each time Im running my app, I programed it to read the photos stored in a specific folder and put them in a DB (Dictionary(string,image)), using:
 
            dI = new DirectoryInfo(@"C:\Users\Me\Desktop\Photos");
            fileInfos = dI.GetFiles("*.jpg", SearchOption.TopDirectoryOnly);
            foreach (FileInfo fi in fileInfos)
            {
                DB.Add(Path.GetFileNameWithoutExtension(fi.FullName), Image.FromFile(fi.FullName));
            }
 
but when im trying to place a photo in a pictureBox using:
pictureBox4.BackgroundImage =  DB["PhotoName"];
 
It shows nothing, blank.
 
that's a drawback, CAUSE,
 
2. I want to use this app in other computers using only the .exe file that stored in the ..\bin\debug\
without each time changing the path the photos are stored...
 
So, how do I create an .exe file for my app that already has all the photos? without worring about them? (problem no' 2)
 
And, how to make sure the photos are shown (problem no' 1)
 
Thank you all!
Posted 28-Mar-13 7:02am
Edited 28-Mar-13 7:08am
v3
Comments
ThePhantomUpvoter at 28-Mar-13 12:14pm
   
1. Probably because you do not have an image named "PhotoName" in the dictionary. And because it's a dictionary, you would want the value, I think.
2. You would either let the user choose a directory to show images from (preferred), or use a well known standard directory for the pictures that the user would have to use, or store images in a directory relative to your program.
RoyDoron at 28-Mar-13 12:20pm
   
1. I have all the photos. I checked many times. and tried other photos..
2. what is option no' 3 you said? "store images in a directory relative to your program" where exactly?
ThePhantomUpvoter at 28-Mar-13 12:40pm
   
Your #1 has nothing to do with anything.
2. means exactly that. Store your images in a path that is relative to your program. Exactly where is up to you. I would have no idea how your program or your system or your users system is setup.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

The chances are that the image is being shown - it certainly is here when I try your code.
But - are you sure you want it in the BackgroundImage? Because if you show a different image in the Image property, you probably won't see your background one...Have you tried setting teh Image property instead?
 

BTW: if you always want the same images, I would build them in as embedded resources to your EXE instead of loading them as separate files.
  Permalink  
Comments
RoyDoron at 28-Mar-13 13:16pm
   
hey OriginalGriff,
 
No, there is no other photo in the background.
Thats the thing, the photos are changing so embedded is not the solution.
OriginalGriff at 28-Mar-13 15:04pm
   
If they are changing, then don't stick them in the bin directory - you may need admin permissions to change them. See here:
http://www.codeproject.com/Tips/370232/Where-should-I-store-my-data
Try using the Image property, or a panel and painting the image yourself (I would probably use that method myself, rather than a PictureBox as it uses fewer resources and can be quicker)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

RoyDoron wrote:
how do I create an .exe file for my app that already has all the photos? without worring about them? (problem no' 2)

 
You can use resources. Adding and Editing resources[^] is very easy Wink | ;)
 
Embeding Image Resources in a project[^]
Code: Retrieving an Image that is an Embedded Resource (Visual C#)[^]
  Permalink  
v2
Comments
RoyDoron at 28-Mar-13 13:18pm
   
Maciej Los,
 
what is the thing with this link.. how it helps me??
and the photos are changing so embedded is not the solution.
Maciej Los at 28-Mar-13 13:23pm
   
This is my answer for your question: how do I create an .exe file for my app that already has all the photos without worring about them? (problem no' 2)
If you want precise answer, ask precise question.
RoyDoron at 28-Mar-13 13:33pm
   
Is this the way to permanenty add the photo folder to my app?
There is nothing in my resource window..
how do I add the folder as a resource?
(note that in my project folder, under Resource there is the photo folder)
Maciej Los at 28-Mar-13 15:33pm
   
See my updated answer ;)
Sergey Alexandrovich Kryukov at 1-Apr-13 10:47am
   
Second one answered, a 5.
—SA
Maciej Los at 1-Apr-13 13:46pm
   
Thank you, Sergey ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 8,284
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,614
3 Maciej Los 4,989
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 28 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100