Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

LoadFromFile in C++ Builder

Posted on 1997-10-27
4
Medium Priority
?
3,525 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
[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
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
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.

715 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