Results 1 to 13 of 13

Thread: Getting the output image path to display

  1. #1

    Thread Starter
    New Member flying pan's Avatar
    Join Date
    Jan 2009
    Location
    Zevija, Spain
    Posts
    14

    Question Getting the output image path to display

    Hi!!

    I designed an interface which calls an executable program written in c. This program needs an input image and outputs another image which has the name: "<the same as the input one>_out". My interface has to display both images (input in picturebox1 and output in picturebox2), I've done so for the input image but now I need to get the path for the output one to display it. I know that there are functions like My.Computer.FileSystem.GetFileInfo() or My.Computer.FileSystem.FindInFiles() but I think they're useless for me, do you think so?

    Do you know any methods or functions to get the path of my output file? Is it possible?

    My knowledge of visual basic .NET is very basic, as you probably have noticed.

    Thank you all!

    If you need more information just let me know and I'll try to explain!

  2. #2
    Lively Member
    Join Date
    Apr 2008
    Posts
    101

    Re: Getting the output image path to display

    It sounds like what I've done for my college project for last year's work, which was in VB6. I asked about it here back then. But I recently made the switch to .NET... It worked by opening a file selection dialog box upon clicking a button, then upon choosing a file it opened a program called ImageMagick using command line and using the path of the image chosen as input, then it outputted the file after shrinking it to the right size and the PictureBox was updated.

    Difficult to explain, but I'll be updating the code to .NET soon. Anyway, I guess that has little to do with what you've asked, but the code could be of use to you if you need it when I update it.

    Your post is a bit ambiguous. Could you explain more about the outputting of the image?

  3. #3

    Thread Starter
    New Member flying pan's Avatar
    Join Date
    Jan 2009
    Location
    Zevija, Spain
    Posts
    14

    Re: Getting the output image path to display

    Ok, I'll try to explain it better :-)

    My interface has two picturebox and two buttons. The first button opens a OpenFileDialog which allows the user to choose the input image, then the image selected is displayed on picturebox1 (until here no problem). The second button calls my executable which modifies the input image chosen and creates an output one in the same directory as the input one with the same name + "_out". Now, what I want to do is display this output image in picturebox2 automatically, I mean without using any more dialogs (just clicking the button, calling .exe and displaying result).

    By now I've been looking for functions which do that (find the output file path) but I've only found the ones which I mentioned on post 1.

    I hope now it's clearer :-S

    If somebody knows how to do it or if it is possible please tell me.

    Thank you!! :-)

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

    Re: Getting the output image path to display

    You manipulate file and folder paths with the IO.Path class so you can get the path of the second image file like so:
    vb.net Code:
    1. Dim outputPath As String = IO.Path.Combine(IO.Path.GetDirectoryName(inputPath), _
    2.                                            String.Format("{0}_out{1}", _
    3.                                                          IO.Path.GetFileNameWithoutExtension(inputPath), _
    4.                                                          IO.Path.GetExtension(inputPath)))
    If you've loaded the original Image by setting the ImageLocation property or calling the Load method of the PictureBox then you can get the inputPath from the ImageLocation property. Otherwise you'll have to remember it yourself by assigning it to a member variable when you open it in the first place.
    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

    Thread Starter
    New Member flying pan's Avatar
    Join Date
    Jan 2009
    Location
    Zevija, Spain
    Posts
    14

    Re: Getting the output image path to display

    Thank you very much jmcilhinney!! It worked!! :-D

    But now I have another problem! I want my program to work with any input image but it only works for images which are in the same directory as the .exe. I know is not .exe problem because I tried without using the interface and it does create the output image. I thought maybe the problem is when calling my executable. I used this (as you also suggested me in another thread):
    vb Code:
    1. Dim returnValue As Process
    2.             returnValue = Process.Start("..\Detector\detector.exe", _
    3.                     String.Concat(ControlChars.Quote, _
    4.                                   OpenFileDialog1.FileName, _
    5.                                   ControlChars.Quote))
    6.             If Not returnValue Is Nothing Then
    7.                 returnValue.WaitForExit()

    Do you know where the problem is? I can't see it!! :-S

    Thank you!!

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

    Re: Getting the output image path to display

    Your program will work with images in any folder if you specify that folder. If you don't specify a folder path then the current working directory is assumed. the current working directory is generally the folder containing the EXE by default but it doesn't have to be and it can change. That's why you should ALWAYS specify an absolute path for a file unless you specifically want to follow the current working directory wherever it might be. That would be a very rare thing so the rule is that you ALWAYS specify an absolute path.
    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

  7. #7

    Thread Starter
    New Member flying pan's Avatar
    Join Date
    Jan 2009
    Location
    Zevija, Spain
    Posts
    14

    Re: Getting the output image path to display

    Hi again!

    Sorry but, how do I specify this absolute path? Because I've done it with the SetCurrentDirectory function and it doesn't work. Do I have to use this?

    I'm sorry but I'm not very familiar to this language, but I'm enjoying learning it! :-)

    Thanks!!

    pd: I would like to specify a general path like "c:\".
    Last edited by flying pan; Jan 8th, 2009 at 10:26 AM.

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

    Re: Getting the output image path to display

    By specifying the full path I mean something like "C:\Folder1\Folder2\File.ext". Exactly how you do that depends on the circumstances. You're rarely, if ever, going to hard-code a path like that. Normally you'll either get the user to specify a path using an OpenFileDialog, SaveFileDialog or FolderBrowserDialog. In that case you'll get the full path from the FileName or SelectedPath property. Other times you'll want to specify a standard folder, which you can do using Environment.GetFolderPath or My.Computer.FileSystem.SpecialDirectories. If you specifically want to refer to a file in the same folder as the executable then you should use Application.StartupPath or My.Application.Info.DirectoryPath to get the folder path and then use IO.Path.Combine or My.Computer.FileSystem.CombinePath to join it to the file name.
    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

  9. #9

    Thread Starter
    New Member flying pan's Avatar
    Join Date
    Jan 2009
    Location
    Zevija, Spain
    Posts
    14

    Re: Getting the output image path to display

    I applied this and I thought it would work but it even can't find the .exe!
    vb Code:
    1. Dim returnValue As Process
    2.             returnValue = Process.Start(IO.Path.Combine(My.Application.Info.DirectoryPath, _
    3.                                                 "Detector\detector.exe"), _
    4.                                         String.Concat(ControlChars.Quote, _
    5.                                                       OpenFileDialog1.FileName, _
    6.                                                       ControlChars.Quote))

    This is not the same as I had before?
    I had this:
    vb Code:
    1. Dim returnValue As Process
    2.             returnValue = Process.Start("..\Detector\detector.exe", _
    3.                     String.Concat(ControlChars.Quote, _
    4.                                   OpenFileDialog1.FileName, _
    5.                                   ControlChars.Quote))

    Maybe I'm using something wrong. :-(

    Sorry I think I didn't understand what you posted before, or maybe I didn't explain well :-) Anyway, what I want to do is make my program work for any image in the computer. Theorically it might do so, but practically it only works with images in the same folder as the .exe.
    Maybe now we can get something. I'm sorry.

    Thank you very much!
    Last edited by flying pan; Jan 8th, 2009 at 11:44 AM.

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

    Re: Getting the output image path to display

    So you're trying to invoke this Detector application and pass it the path of an image file, correct? That application then creates the copy, correct? Where is this Detector.exe located? I'm guessing that it's not under your program folder, so it's no good using My.Application.Info.DirectoryPath as the root. Is it safe to assume that it will always be located in a folder named Detector under the Program Files folder? If so then that's the path you should specify:
    vb.net Code:
    1. IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.ProgramFiles, _
    2.                 "Detector\detector.exe")
    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

  11. #11

    Thread Starter
    New Member flying pan's Avatar
    Join Date
    Jan 2009
    Location
    Zevija, Spain
    Posts
    14

    Re: Getting the output image path to display

    Quote Originally Posted by jmcilhinney
    So you're trying to invoke this Detector application and pass it the path of an image file, correct? That application then creates the copy, correct?
    Yesss. I'm exactly doing this.

    My detector.exe is located in a folder named "Detector" in the same folder than the aplication for the interface. So if the interface aplication is on "C:\My Project\Interface\Interface.exe" then the .exe is on "C:\My Project\Interface\Detector\detector.exe"
    So it's not located in Program Files folder.

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

    Re: Getting the output image path to display

    I don't see how that's possible. The double dots in your original code seem to imply that you want to go up one level and then into the Detector folder. If the Detector folder was in the same folder as your EXE then the first code snippet from post #9 would work and the second wouldn't.

    I'm guessing that you have manually gone into the 'bin' folder under your project and added a Detector folder there. Am I correct? That's no good because that's not where it will be once it's deployed.
    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

  13. #13

    Thread Starter
    New Member flying pan's Avatar
    Join Date
    Jan 2009
    Location
    Zevija, Spain
    Posts
    14

    Re: Getting the output image path to display

    Ok! Finally I put the Detector folder in Program Files and called the executable using:
    vb Code:
    1. Dim returnValue As Process
    2.             returnValue = Process.Start(IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.ProgramFiles, _
    3.                                                         "Detector\detector.exe"), _
    4.                                                         String.Concat(ControlChars.Quote, _
    5.                                                                       OpenFileDialog1.FileName, _
    6.                                                                       ControlChars.Quote))

    and it worked!! Now I don't have any more problems

    Thank you very much jmcilhinney!! You're a machine!haha

    If I have more problems I'll post a new thread or reply here.

    Thanks again! :-$

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