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

Working with GIF images in Delphi
Need to display an animated GIF image in a Delphi application?

By Zarko Gajic, About.com

Working with GIF images in Delphi

Working with GIF images in Delphi

Need to display an animated GIF image in a Delphi application? Even though Delphi does not natively support GIF image files formats (like BMP or JPEG) there are a few great (free source) components available on the Net, which add the ability to display and manipulate GIF images at run as well as at design time to any Delphi application. Natively, Delphi supports BMP, ICO, WMF and JPG images - these can be loaded into a graphic-compatible component (such as TImage) and used in an application.

Natively, Delphi supports BMP, ICO, WMF and JPG images - these can be loaded into a graphic-compatible component (such as TImage) and used in an application.

Note: As of Delphi version 2006 GIF format is supported by the VCL. To use animated GIF images you would still need a third-party control.

GIF - Graphics Interchange Format

GIF is the most widely supported (bitmap) graphics format on the Web, both for still images and for animations.

The GIF format incorporates a compression scheme to keep files sizes at a minimum, and GIF files are limited to 8-bit (256 or fewer colors) color palettes. There are a few slight variants of the basic GIF file format that add support for transparent color, and support for the interlaced GIF graphics (GIF87a and GIF89a).

Using in Delphi

Natively, Delphi does not support GIF images, due to some legal copyright issues. What this means, is that when you drop a TImage component on a form, use the Picture Editor (click the ellipsis button in the Value column for properties, such as the Picture property of TImage) to load an image into the TImage, you will not have an option to load GIF images.

Fortunately, there are a few third-party implementation on the Internet that provide full support for the GIF format:

  • TGIFImage[1] - free with source (a version of Anders Melander's TGIFImage ported to Delphi 7). Full TGraphic implementation of the GIF graphics format. Reads, writes and displays animated and transparent GIFs and can convert to and from any format supported by TGraphic (e.g TBitmap, TJPEGImage, TIcon, TMetaFile etc.). Implements the complete GIF87a and GIF89a specification and most common GIF extensions. Advanced features include:
    • Integrates with TPicture to add GIF support to the TImage, TOpenPictureDialog and TSavePictureDialog components. Also works at design time.
    • Imports images with more than 256 colors using color quantization and 6 different dithering methods (e.g. floyd s!teinberg).
    • Multi threaded drawing engine.
    • GIF optimizer reduces the size of your GIFs.
    • GIF to AVI and AVI to GIF converter.

  • TGIFImage[2] - free without the source for non-commercial use. Another implementation of the GIF graphics format. Features include:
    • Fully compliant with the GIF87a and GIF89a standards. Will also try to decode unknown versions, as recommended in the specifications.
    • Can decode and display animated GIF's.
    • Can decode and display transparent GIF's.
    • Can decode and display interlaced GIF's.
    • Loading from files, streams or resources
    • Saving to files or streams. Easy saving of animations or single-image GIF's, including full transparency and interlacing support.

  • GraphicEx image library - an addendum to Delphi's Graphics.pas to enable your application to load many common image formats. This library is primarily designed to load images as background (buttons, forms, toolbars) and textures (DirectX, OpenGL) or for image browsing and editing purposes as long as you don't need to save images. Currently only TTargaGraphic also supports saving an image. GraphicEx is open source under the Mozilla Public License (MPL).
That's about it. Now all you have to do, is to download one of the components, and start using gif images in your applications.
You can, for example:
Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

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

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Advanced Delphi Techniques
  5. Graphics Programming
  6. Picture file formats
  7. Working with GIF images in Delphi

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

All rights reserved.