Results 1 to 6 of 6

Thread: Open a file

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    25

    Open a file

    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.
    Last edited by Ixl2; Jan 22nd, 2006 at 02:13 PM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Open a file

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    25

    Re: Open a file

    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.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Open a file

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    Lively Member
    Join Date
    Jan 2006
    Posts
    66

    Re: Open a file

    I think he wants this.

    Code:
    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

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    25

    Re: Open a file

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width