Click to See Complete Forum and Search --> : Open a file
Ixl2
Jan 22nd, 2006, 12:46 PM
Hi
Im in the process of making my first useful C# application and have ran into a little truble i need to know how to choose pictures and display the path of the choosen pics in a text box for later use (The text box's is setup for a global veriable named path1 and path2) when they can be manipulated. How can i do this?
Thanks for the help
P.s
What the end goal is to take two or more pics and join them as one.
jmcilhinney
Jan 22nd, 2006, 05:34 PM
I'm afraid that it's not really clear what you want from your description. If you want the user to specify a file location then you would use an OpenFileDialog. If you want to create an Image object from a file you would normally call Image.FromFile. Once you create that Image object it has no recollection of where it came from, so it is up to you to save the path to a variable if you are going to want to use it later.
Ixl2
Jan 22nd, 2006, 07:07 PM
Hi
Sorry, ok im trying to make an app where the user can choose two or more pictures (i wish to display the path to the choosen pictures in a texbox) once the required pictures are choosen by the user the application will then join the pictures as one and save the new picture. I've got no idea how to display the choosen file paths into a textbox nor do i know how to join the picture together to make a new combined picture.
Here is some sort of diagram :)
pic1 + pic2 = NewPic
pic1 path = C:\My Pics\otherpic.jpg
Pic2 path = F:\New Folder\Pics\mypic.jpg
Display the "F:\New Folder\Pics\mypic.jpg" in a text box and so on.
Hope this is a little more clear.
jmcilhinney
Jan 22nd, 2006, 07:20 PM
Like I said, you would have the user select a file using an OpenFileDialog. The path of the file they chose can be retrieved from the FileName property, which you can then assign to the Text property of a TextBox. You can open the image either by calling Image.FromFile with the file path or creating a new Bitmap object from the file path. Note that these two methods will both lock the file until the Image object is Disposed. There are other methods but I'll let you investigate them yourself. As for combining the images, the Bitmap class has members that will allow you to copy a portion of one Bitmap to another.
{FPP}
Jan 22nd, 2006, 07:55 PM
I think he wants this.
OpenFileDialog ofd = new OpenFileDialog();
ofd.ShowDialog();
textBox1.Text = ofd.FileNmae;//set the textbox text of the path they selected.
//now set the picture to the picture box
pictureBox1.Image = Image.FromFile(textBox1.Text);//have the path be the textbox
from what i understand thats waht he wants....
That will set the path they selected into a textbox. And then set that into the picturebox
Ixl2
Jan 22nd, 2006, 08:17 PM
thanks for the repliys i worked out every thing but joining the two pics or so and saving it out as a new pic.
Help on this part would be great.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.