Solved

loading bmp from file to TImage

Posted on 2002-04-20
2
608 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
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

773 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