Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

LoadFromFile in C++ Builder

Posted on 1997-10-27
4
Medium Priority
?
3,584 Views
Last Modified: 2011-10-03
In my program i try to load several Bitmaps while the program is running. In Delphi 2.0 exists the method
LoadFromFile. Using this method the following code works
Image1.Picture.LoadFromFile('C:\pictures\example.bmp');.
The analogous code using the -> operator instead of the . operator doesn't work. Who can me post an exmple using this
method in Borland C++ builder environment. Thank you
yours Thorsten
0
Comment
Question by:thorsten
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
cph earned 400 total points
ID: 1172116
To load a bitmap into an image control's picture pass the name of a bitmap file to the picture's LoadFromFile method:

void __fastcall TForm1::FormCreate(TObject *Sender)
{
   Image1->Picture->LoadFromFile("c:\\windows\\athena.bmp");
}

The picture recognizes .BMP as the standard extension for bitmap files, so it creates its graphic as a TBitmap, then calls that graphic's LoadFromFile method. Because the graphic is a bitmap, it loads the image from the file as a bitmap.

Hope this help,

CpH
0
 
LVL 1

Expert Comment

by:cph
ID: 1172117
Oupps... here is the complete source file :-)

//---------------------------------------------------------------
#include <vcl\vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
      : TForm(Owner)
{
}
//---------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)
{
   Image1->Picture->LoadFromFile("c:\\windows\\athena.bmp");
}
//---------------------------------------------------------------

Sorry about this,
CpH
0
 

Author Comment

by:thorsten
ID: 1172118
Hallo cph!
Thank you for your answer. But I wonder why I have to use the double backslash. Why is this not written  in the help file.
Yours Thorsten.  
0
 
LVL 2

Expert Comment

by:maggc
ID: 22441060
Double backslash must be used because the single backslash is a special escape character. It is not accepted.

The double backslash is in fact only 1 byte of code!

char c;
c = '\\'; // works! a character can take only 1 byte

So:

c:\1.txt  --> c:\\1.txt   (in your code)

\\server\share\1.txt  --> \\\\server\\share\\1.txt
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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
Course of the Month11 days, 2 hours left to enroll

885 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