Solved

loading bmp from file to TImage

Posted on 2002-04-20
2
616 Views
Last Modified: 2010-05-18
I am using the code below to try and load a filepath to a bmp file from a txt file. It compiles fine but when I get to the LoadFromFile stmt I get a runtime error "EFOpenError Cannot open file" and then it displays the path it should open so it is reading it correctly. I am using Borland C++ Builder.  

Can anyone tell me where I have gone wrong please


ifstream in ("Test.txt");    
char s[_MAX_PATH];

if( ! in )
{
  Application->MessageBox("Cannot open file.",
   "MessageBox",MB_OK + MB_DEFBUTTON1);
}
else
{
  Graphics::TBitmap *Bitmap1 = new Graphics::TBitmap();
  in.getline(s,_MAX_PATH);
  Bitmap1->LoadFromFile(s);
  Image1->Picture->Bitmap = Bitmap1;
}
in.close();
0
Comment
Question by:sylvrynne
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 6

Accepted Solution

by:
thienpnguyen earned 100 total points
ID: 6955829
Maybe, s contains some spaces before or (after)image file. For example,  s = "   c:\x.bmp" is wrong filename

For sure, the filename is correct, you can use access(...) . The following is demo code

    ifstream in ("Test.txt");
    char s[_MAX_PATH];

    if( ! in )
    {
        Application->MessageBox("Cannot open file.",
            "MessageBox",MB_OK + MB_DEFBUTTON1);
    }
    else
    {
        Graphics::TBitmap *Bitmap1 = new Graphics::TBitmap();
        in.getline(s,_MAX_PATH);
        if( access(s,0) != 0 )
        {
            String msg = String("\"") + s + "\"";
            Application->MessageBox("Cannot open image.",
                msg.c_str(),MB_OK );
            return;
        }

        Bitmap1->LoadFromFile(s);
        Image1->Picture->Bitmap = Bitmap1;
    }
    in.close();

0
 

Author Comment

by:sylvrynne
ID: 6956921
You will never believe what it was ... the path had " " marks around it .... just too late last night to see it in the text file  thanx for your help
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

691 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