Image.fromfile 2005

Posted on 2007-07-31
Last Modified: 2013-11-26
Dim newImage As Image = Image.FromFile("image.bmp")

On the above, where does the image.bmp need to be?  I have it in my bin folder and in one project it works and in the other I get the message it's not there?
Question by:bergertime
    LVL 38

    Accepted Solution

    If you don't specify a path, I think it will default to the start up directory of the shortcut that the IDE was run from.  You are better off specifying the path.  When it's in the same folder as the EXE, I usually use:

    Dim Path as string = System.AppDomain.CurrentDomain.BaseDirectory() & "image.bmp"

    Dim newImage As Image = Image.FromFile(Path)
    LVL 62

    Assisted Solution

    by:Fernando Soto
    image.bmp needs to be a fully qualified path and file name so that it can be found.

    For example
        Dim newImage As Image = Image.FromFile("C:\Program File\MyApp\image.bmp")

    LVL 18

    Assisted Solution

    If this image will be located in same folder as your application ,then you will use Applicatio.StartupPath
    Dim newImage As Image = Image.FromFile(Application.StartupPath & "\image.bmp")

    LVL 62

    Expert Comment

    by:Fernando Soto
    Hi Bob;

    I would like to see a resolution to this question because all three experts had basically the same solution. I would like to see a point split.

    LVL 2

    Author Comment

    Sorry guys, I had moved on and forgot about this question being open.  I gave Paul the lions share since he was first to post and he gave a more detailed answer.  Again thanks to all who posted a solution.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now