Solved

LoadFromFile in C++ Builder

Posted on 1997-10-27
4
3,140 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 100 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

744 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

13 Experts available now in Live!

Get 1:1 Help Now