Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

loading bmp from file to TImage

Posted on 2002-04-20
2
Medium Priority
?
624 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 400 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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 pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

609 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