Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I want to display an image in my mobile application.I have picturebox.I have to display an image in that.

pictureBox1.Image = new Bitmap("\\My Documents\\My Pictures\\waterfall.jpg");


This is working.Because it is internal image for the emulator. While trying for custom image it is not displaying.I didn't get the path of that image where it is deploying the image in the project.any one can help? (WM 5.0)
Posted
Updated 5-Apr-11 20:38pm
v2

1 solution

I'm not quite sure what you are trying to do that is giving you a problem.

If you do this:
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == DialogResult.OK)
    {
    pictureBox1.Image = new Bitmap(ofd.FileName);
    }
It works. If you specify the path to the image directly, it works.
pictureBox1.Image = new Bitmap(@"\My Documents\My Pictures\Flower.jpg");
So what am I missing?


"From local system folder i want take an image and i want to place it as header of that app. will it work?"

Yes. All you have to do is provide the path:
pictureBox1.Image = new Bitmap(@"\Windows\Flower.jpg");
Or are you trying to take it from your PC? Because if so, that won't work when you move out of the emulator and into the real thing...


"its giving same "file not found error".Image is in images folder of the project.I think Before this the image need to copy to the emulator?..if so, how to copy that image to emulator..can you tell?"

1) In your project open the Images folder in Solution Explorer.
2) Highlight the image you want.
3) In the properties pane, set:
3a) Build Action: Content
3b) Copy to Output Directory: Copy If Newer

Then in your code:
string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
pictureBox1.Image = new Bitmap(path + @"\Images\MyImageFile.jpg");
 
Share this answer
 
v3
Comments
Mada Naga Sankar 6-Apr-11 3:19am    
From local system folder i want take an image and i want to place it as header of that app. will it work?
OriginalGriff 6-Apr-11 4:18am    
Answer updated
Mada Naga Sankar 6-Apr-11 4:22am    
its giving same "file not found error".Image is in images folder of the project.I think Before this the image need to copy to the emulator?..if so, how to copy that image to emulator..can you tell?
I am not getting the path where it is storing....
OriginalGriff 6-Apr-11 4:41am    
Answer updated
Mada Naga Sankar 6-Apr-11 4:46am    
Thank You...my problem solved......

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900