Help & Manual authoring tool
By default, TImage takes the color of the bottom-left pixel of an image as the transparent color when the Transparent property is set to True, but you can use the TransparentColor and TransparentMode properties to specify the invisible color

Setting the invisible color of a transparent image

Copyright © 2000 Ernesto De Spirito

InstallAWARE - MSI without rocket science

Transparent image

The TImage component has a Transparent property that when set to True displays the bitmap of the Picture property transparently. To do this, it takes the color of the bottom-leftmost pixel and treates all pixels of this color as invisible (you can see the objects begind the TImage).

For example, this bitmap...

...would be seen this way:

Since the pixel of the lower-left corner is green, all green pixels are made invisible. But, what if we wanted to see the image this way?

TransparentColor and TransparentMode

To achieve this result, we have to set the TransparentColor and TransparentMode properties of the bitmap at run-time, for example when the form is created:

procedure TForm1.FormCreate(Sender: TObject);
begin
  with Image1.Picture.Bitmap do begin
    TransparentColor := clMaroon;
    TransparentMode := tmFixed;
  end;
end;

TransparentColor is the color (Color) that will be considered invisible. For example, we can use a constant (like $00800000, clMaroon or clBtnFace) or we can get the color from some pixel of the bitmap (like Canvas.Pixels[1,1]).

TransparentMode is tmAuto by default, meaning it takes the color of the pixel in the lower-left corner, and we have to set it to tmFixed (the other possible value) to tell the bitmap to use the color stored in the TransparentColor property as the invisible color.

JfControls Library - for Delphi and C++ Builder
Copyright © 2000/2006 Ernesto De Spirito.   All rights reserved.