 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
SVC Guest
|
Posted: Tue May 17, 2005 9:44 pm Post subject: ImageList |
|
|
Greetings,
I am trying to load an image (for splash) based on a macro, i.e.:
#ifdef TEST
Image1->Picture->LoadFromFile(".\splash\Test_Splash.jpg");
#else
Image1->Picture->LoadFromFile(".\splash\Real_Splash.jpg");
#endif
This method requires having the actual jpeg file available otherwise an
exception is thrown.
Is there a way of including the graphical files in the executable and
accessing through an index?
Thanks,
S.
|
|
| Back to top |
|
 |
JD Guest
|
Posted: Tue May 17, 2005 10:01 pm Post subject: Re: ImageList |
|
|
"SVC" <svchamlian (AT) hotmail (DOT) com> wrote:
| Quote: |
Is there a way of including the graphical files in the
executable
|
Yes, you can include the image in a resource file and it will
be compiled into the executable.
| Quote: | and accessing through an index?
|
It's not actually an index but the logic is the same. Look at
LoadFromResourceID and/or TResourceStream.
~ JD
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Tue May 17, 2005 10:02 pm Post subject: Re: ImageList |
|
|
"SVC" <svchamlian (AT) hotmail (DOT) com> wrote
| Quote: | This method requires having the actual jpeg file available otherwise
an exception is thrown.
|
You could always check for the file's existance before trying to load it.
Look at the FileExists() function.
| Quote: | Is there a way of including the graphical files in the executable
and accessing through an index?
|
TPicture has no provisions available for loading images from resources. You
will have to load the image manually. Since you are only loading JPG
images, you can instantiate an instance of TJPEGImage, then call its
LoadFromStream() method, using a TResourceStream to access the image data
from the application's resources, and then finally assign the TJPEGImage to
TPicture's Graphic property. For example:
TResourceStream *Stream = new TResourceStream(HInstance,
#ifdef TEST
FirstID,
#else
SecondID,
#endif
RT_RCDATA);
try
{
TJPEGImage *JPG = new TJPEGImage;
try
{
JPG->LoadFromStream(Stream);
Image1->Picture->Graphic = JPG;
}
__finally {
delete JPG;
}
}
__finally {
delete Stream;
}
Do note that the above makes multiple copies of the JPG image, since
assigning the Graphic property makes a copy of the graphic rather than
taking ownership of it. If you don't want the extra copy, you can do the
following instead:
TResourceStream *Stream = new TResourceStream(HInstance,
#ifdef TEST
FirstID,
#else
SecondID,
#endif
RT_RCDATA);
try
{
TJPEGImage *JPG = new TJPEGImage;
try
{
// yes, this is assigning a blank image. This is to force the
Graphic
// property to be the correct class type before then loading the
// image data into it...
Image1->Picture->Graphic = JPG;
}
__finally {
delete JPG;
}
Image1->Picture->Graphic->LoadFromStream(Stream);
}
__finally {
delete Stream;
}
Gambit
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Tue May 17, 2005 11:41 pm Post subject: Re: ImageList |
|
|
"JD" <nospam (AT) nospam (DOT) com> wrote
| Quote: | Look at LoadFromResourceID
|
That only applies to TBitmap, which cannot load JPG images.
Gambit
|
|
| Back to top |
|
 |
wgy Guest
|
Posted: Wed May 18, 2005 1:56 pm Post subject: Re: ImageList |
|
|
I guess that he meant the ship the exe without the image files. You can load
image at design time into image list, and then reference the images by their
index. But the exe file size is much bigger than JPG file bundle with the
exe because TImagelist store image in bmp mode. It doesn't matter since you
installation will zip the file anyway.
"SVC" <svchamlian (AT) hotmail (DOT) com> wrote
| Quote: | Greetings,
I am trying to load an image (for splash) based on a macro, i.e.:
#ifdef TEST
Image1->Picture->LoadFromFile(".\splash\Test_Splash.jpg");
#else
Image1->Picture->LoadFromFile(".\splash\Real_Splash.jpg");
#endif
This method requires having the actual jpeg file available otherwise an
exception is thrown.
Is there a way of including the graphical files in the executable and
accessing through an index?
Thanks,
S.
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|