How to use transparent picture on Delphi TImage component

Published on Sunday, June 20th, 2010 by Maurizio Mutti

The problem

In modern graphical user interfaces it’s a must to use picture with transparency, so that they can adapt to gradient used in form or tabs in the backgrounds.
Unfortunately Delphi’s TImage component (at least up to Delphi 2007) does not support png files so the only possibility seems to use gif transparency.
But as you probably knows gif format does not allow alpha channel transparency so the result does not look nice.

The solution

Fortunately a nice workaround exist, Delphi’s TImage component support alpha transparency on icon files (.ico).
To use good looking png files on GUI we just need to convert them into icon file and then load it into the component.
To accomplish this task in an easy way, I use IcoFx a free software for create and edit icons.

The steps in detail:

  • Import the png file into IcoFx.
    File -> Import Image… -> pick the .png file
    In the new image dialog, select “True colors + Alpha channel” and the desired size.
  • Save the converted icon file.
    File -> Save As…
  • Load the picture inside the TImage component.
Share

Tags: , ,

Leave a Reply