BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

ImageList

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage)
View previous topic :: View next topic  
Author Message
SVC
Guest





PostPosted: Tue May 17, 2005 9:44 pm    Post subject: ImageList Reply with 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
JD
Guest





PostPosted: Tue May 17, 2005 10:01 pm    Post subject: Re: ImageList Reply with quote




"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





PostPosted: Tue May 17, 2005 10:02 pm    Post subject: Re: ImageList Reply with quote




"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





PostPosted: Tue May 17, 2005 11:41 pm    Post subject: Re: ImageList Reply with quote


"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





PostPosted: Wed May 18, 2005 1:56 pm    Post subject: Re: ImageList Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.