Working with GIF images in Delphi

Illustration of Delphi programming language code displayed on three monitor
teguhjatipras / Getty Images

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 graphics-compatible component (such as TImage) and used in an application.

It's important to note that, 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.

GIFs--or Graphics Interchange Formats--are the most widely supported (bitmap) graphics format on the Web, both for still images and for animations.

Using in Delphi

Natively, Delphi (until version 2007) 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 implementations on the Internet that provide full support for the GIF format:

  • TGIFImage: 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-​Steinberg).
    • Multi-threaded drawing engine.
    • GIF optimizer reduces the size of your GIFs.
    • GIF to AVI and AVI to GIF converter.
  • 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:

    • Store GIF images in a database table. You'll need the GIF image's "magic numbers."
    • Show GIF graphics as Glyph on a SpeedButton.
    • Store GIF graphics and an HTML file as a resource inside am exe.
    Format
    mla apa chicago
    Your Citation
    Gajic, Zarko. "Working with GIF images in Delphi." ThoughtCo, May. 21, 2018, thoughtco.com/working-with-gif-images-in-delphi-1058070. Gajic, Zarko. (2018, May 21). Working with GIF images in Delphi. Retrieved from https://www.thoughtco.com/working-with-gif-images-in-delphi-1058070 Gajic, Zarko. "Working with GIF images in Delphi." ThoughtCo. https://www.thoughtco.com/working-with-gif-images-in-delphi-1058070 (accessed June 18, 2018).