Board index » cppbuilder » Imagelist

Imagelist


2003-08-06 10:29:06 PM
cppbuilder99
I'm a beginner with cpp builder. I've this problem: i'm not able to
add icons in my imagelist.
I can't find the directory containing the icons. Can someone help me?
My c++ Builder is the 6 version. thnk's.
Claudio
 
 

Re:Imagelist

hi,
i'm trying to use a BMP from a TImagelist to put it in the glyph property of a button. the code is like this :
imagelist1.getbitmap(1,button1.glyph);
the code works, but the image in the button never is exact the same as the image in the imagelist. there is some differences in color.
so the question is : how to get a bitmap in the imagelist and it looks exact as in the imagelist ?
thanks in advance
 

Re:Imagelist

Hi, viana:
I think you should to use a TSpeedButton instead of TButton. I loaded
the bitmap from TImageList was successful. My codes like this:
procedure TForm1.Button1Click(Sender: TObject);
var
Bmp: TBitmap;
begin
Bmp := TBitmap.Create;
try
ImageList1.GetBitmap(0, Bmp);
{ Maybe you need the following line. The transparent color
should be same as the Icon in TImageList. }
Bmp.TransprarentColor := clWhite;
SpeedButton1.Glyph.Assign(Bmp);
finally
Bmp.Free;
end;
end;
The codes above was worked with Delphi 5.
Best regards.
Xiaoguang
"viana" < XXXX@XXXXX.COM >wrote in message
Quote

hi,

i'm trying to use a BMP from a TImagelist to put it in the glyph property
of a button. the code is like this :

imagelist1.getbitmap(1,button1.glyph);

the code works, but the image in the button never is exact the same as the
image in the imagelist. there is some differences in color.

so the question is : how to get a bitmap in the imagelist and it looks
exact as in the imagelist ?

thanks in advance
 

{smallsort}

Re: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.
 

Re:Imagelist

"SVC" < XXXX@XXXXX.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
 

Re:Imagelist

"SVC" < XXXX@XXXXX.COM >wrote in message
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
 

Re:Imagelist

"JD" < XXXX@XXXXX.COM >wrote in message
Quote
Look at LoadFromResourceID
That only applies to TBitmap, which cannot load JPG images.
Gambit
 

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" < XXXX@XXXXX.COM >wrote in message
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.