Board index » delphi » Add Run time images to TImageList

Add Run time images to TImageList

I need to build up a TImageList dynamically, the problem I am having is
that the transparancy does not seem to work.

Put a TToolbar on top and create a button, Create an image list with one

image and load that image, set the ttoolbutton item index = 0;

Everything is displayed properly, now do

procedure TForm1.Button2Click(Sender: TObject);
Var
  b : TBitmap;
begin
   b := TBitmap.Create;
   ImageList1.GetBitmap(0, b);
   b.Transparent := true;
   b.TransparentMode := tmAuto;
   ImageList1.Add(b,nil);
   ToolButton1.ImageIndex := 1;
   b.free;
end;

What I think I have done is added the same bitmap to the image list and
then set the button to display that image.  They should look the same
but they do not;  there is
no transparancy.   Any idea how to solve this problem?

I cannot color the background the same as the button face because
graying on disable does not work properly then.

Thank

-John_Mer...@Brown.EDU

 

Re:Add Run time images to TImageList


Transparency for TImageList can work in 2 different ways:
1. The BkColor in the images is treated as the background color (DrawStyle =
dsNormal and BkColor <> clNone)
2. A second black & white image is created that holds the information on
what part of the bitmap is the background (DrawStyle = dsTransparent or
BkColor = clNone)

Transparency for TBitmap can also work in 2 different ways:
1. The TransparentColor in the image is treated as the background color
(TransparentMode = tmFixed)
2. The color of the bottom-leftmost pixel is treated as the background color
(TransparentMode = tmAuto)

To get this working you should set the TransparentColor and use
TransparentMode tmFixed. Next you should use AddMasked with the used
TransparentColor.

"John Mertus" <John_Mer...@Brown.EDU> schreef in bericht
news:3AA774AF.271A6CEA@Brown.EDU...

Quote
> I need to build up a TImageList dynamically, the problem I am having is
> that the transparancy does not seem to work.

> Put a TToolbar on top and create a button, Create an image list with one

> image and load that image, set the ttoolbutton item index = 0;

> Everything is displayed properly, now do

> procedure TForm1.Button2Click(Sender: TObject);
> Var
>   b : TBitmap;
> begin
>    b := TBitmap.Create;
>    ImageList1.GetBitmap(0, b);
>    b.Transparent := true;
>    b.TransparentMode := tmAuto;
>    ImageList1.Add(b,nil);
>    ToolButton1.ImageIndex := 1;
>    b.free;
> end;

> What I think I have done is added the same bitmap to the image list and
> then set the button to display that image.  They should look the same
> but they do not;  there is
> no transparancy.   Any idea how to solve this problem?

> I cannot color the background the same as the button face because
> graying on disable does not work properly then.

> Thank

> -John_Mer...@Brown.EDU

Re:Add Run time images to TImageList


Thank you very much, this worked!
Quote
"M.H. Avegaart" wrote:
> Transparency for TImageList can work in 2 different ways:
> 1. The BkColor in the images is treated as the background color (DrawStyle =
> dsNormal and BkColor <> clNone)
> 2. A second black & white image is created that holds the information on
> what part of the bitmap is the background (DrawStyle = dsTransparent or
> BkColor = clNone)

> Transparency for TBitmap can also work in 2 different ways:
> 1. The TransparentColor in the image is treated as the background color
> (TransparentMode = tmFixed)
> 2. The color of the bottom-leftmost pixel is treated as the background color
> (TransparentMode = tmAuto)

> To get this working you should set the TransparentColor and use
> TransparentMode tmFixed. Next you should use AddMasked with the used
> TransparentColor.

> "John Mertus" <John_Mer...@Brown.EDU> schreef in bericht
> news:3AA774AF.271A6CEA@Brown.EDU...
> > I need to build up a TImageList dynamically, the problem I am having is
> > that the transparancy does not seem to work.

> > Put a TToolbar on top and create a button, Create an image list with one

> > image and load that image, set the ttoolbutton item index = 0;

> > Everything is displayed properly, now do

> > procedure TForm1.Button2Click(Sender: TObject);
> > Var
> >   b : TBitmap;
> > begin
> >    b := TBitmap.Create;
> >    ImageList1.GetBitmap(0, b);
> >    b.Transparent := true;
> >    b.TransparentMode := tmAuto;
> >    ImageList1.Add(b,nil);
> >    ToolButton1.ImageIndex := 1;
> >    b.free;
> > end;

> > What I think I have done is added the same bitmap to the image list and
> > then set the button to display that image.  They should look the same
> > but they do not;  there is
> > no transparancy.   Any idea how to solve this problem?

> > I cannot color the background the same as the button face because
> > graying on disable does not work properly then.

> > Thank

> > -John_Mer...@Brown.EDU

Other Threads