Delphi Programming

  1. Home
  2. Computing & Technology
  3. Delphi Programming

Apply Custom Transparent Color for the TImage Delphi Control

By Zarko Gajic, About.com

Custom TImage Transparent Color

Custom TImage Transparent Color

The Transparent property of the TImage Delphi control specifies whether the objects behind the image should show through the background of the image.

When Transparent is True, by design, the bottom-left pixel and all the pixels of the same color as "invisible".

Custom Color TImage Transparency

If you do not want the color of the bottom-left pixel to specify which image color should be "transparent" - you can set the TransparentColor property programmatically.

Here's an example with 3 TImage controls all displaying the same bitmap image: red circled black x with magenta "surrounding".

Image 1 has Transparency set to False.

Image 2 has Transparency set to True.

Image 3 has Transparency set to True. Plus: TransparentColor and TransparentMode are programmatically set. The pixel used to set the transparent color is positioned in the middle of the image (original size 48 x 48 px.)

procedure TForm1.FormCreate(Sender: TObject) ;
begin
  Image1.Transparent := False;

  Image2.Transparent := True;

  Image3.Transparent := True;

  with Image3.Picture.Bitmap do
  begin
    //middle of the image
    TransparentColor := Canvas.Pixels[24,24];
    //actually not needed
    TransparentMode := tmFixed;
  end;
end;
Note 1: If TransparentColor is assigned, the TransparentMode is automatically set to tmFixed so that the new transparent color can be used later. If you want TransparentColor to disregard any assignments and return the bottom left most pixel color again, set TransparentMode to tmAuto.

Note 2: the image used comes with Delphi, you can locate it in the Program Files\Common Files\Borland Shared\Images\GlyFX folder.

Delphi tips navigator:
» TFrame.OnCreate: how to Implement the OnCreate event for a Delphi TFrame object
« Display Custom Hints for TListView Sub Items

More Delphi Programming Quick Tips
Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming

About.com Special Features

Build Your Own Website

Step-by-step advice on how to do everything from choosing a Web host to promoting your content. More >

Connect Your Home Computers

Easy ways to connect two computers for networking purposes. More >

Delphi Programming

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Using VCL Components
  5. TImage
  6. Apply Custom Transparent Color for the TImage Delphi Control

©2009 About.com, a part of The New York Times Company.

All rights reserved.