Frequently Asked Questions 

This is the growing list of questions that people most often ask about TGIFImage.
Please read it carefully before you mail me questions about TGIFImage.


Question I have made a small application that displays a GIF in a TImage component. The GIF displays fine in design mode in Delphi but nothings shows up when the application is running. What's wrong?
Answer
Delphi Delphi
You have probably forgotten to include the "gifimage" unit in your uses clause. Unless you add gifimage to one of the uses clauses in your application (doesn't matter where), there is no way your application can know what to do with a GIF.

 
C++ Builder C++ Builder
You need to include the "gifimage" module in your project. Unless the gifimage module (gifimage.pas) is added to your project, it will not get linked into your application, and your application will not know how to handle GIFs.

 
If your GIF shows at design time it must mean that you have included gifimage.pas in a package that is active at design time (most packages are). If it then doesn't show at run time the package probably isn't active at run time meaning that you haven't selected to compile and link with run time packages.

Question Why aren't GIF files listed as a file type in my TOpenPictureDialog or TSavePictureDialog?
Answer Because you haven't told TOpenPictureDialog and TSavePictureDialog about TGIFImage...
The following code snippets shows how to use a TOpenPictureDialog to load GIF files. The same technique can be used for TSavePictureDialog, TOpenDialog and TSaveDialog.

Delphi Delphi
        OpenPictureDialog1.DefaultExt := GraphicExtension(TGIFImage);
        OpenPictureDialog1.Filter := GraphicFilter(TGIFImage);
        if OpenPictureDialog1.Execute then
          { load the GIF somehow }

 
C++ Builder C++ Builder
        OpenPictureDialog1->DefaultExt = GraphicExtension(__classid(TGIFImage));
        OpenPictureDialog1->Filter = GraphicFilter(__classid(TGIFImage));
        if (OpenPictureDialog1->Execute)
          { load the GIF somehow }

 
See the Convert demo for an example of this. The GraphicExtension and GraphicFilter functions are documented in the VCL online help.


Question Do I need to add TGIFImage to a package before I can use it?
Answer It depends... You don't need to install gifimage into a package unless you need GIF support at design time or wish to put your GIF support in a run time package.
If you would like to be able to load GIF files into TImage components at design time you should install TGIFImage as a component (see the Installation Instructions).

Question I have converted a bitmap to a GIF using the TGIFImage.Assign method but the colors of the GIF are all wrong. Is this a bug?
Answer No, probably not.
The problem is that your bitmap is in a format that TGIFImage doesn't directly support, namely 15, 16, 24 or 32 bit format.

In order to be able to import bitmaps with more than 256 colors, TGIFimage first reduces the potential number of colors to a maximum of 256 and then converts the bitmap to 8 bit format. This must be done because the GIF format doesn't support more than 256 colors.
You can control the method TGIFImage uses to choose the colors that are used in the final GIF by setting the GIFImageDefaultColorReduction variable.


Question I have heard that your TGIFImage is the greatest GIF component around. Is this true?
Answer Yes, it is absolutely true.
(Isn't it just great when you can write your own FAQ?)

Question I'm getting "Canvas does not allow drawing" exceptions and all sorts of access violations when I use TGIFImage. What am I doing wrong?
Answer It sounds like you are using the goDirectDraw and goAsync options and are forgetting to kill the paint thread before you delete the canvas the thread is painting on.

When you use the goDirectDraw option, it is very important to stop the paint thread before the canvas is deleted. The reason for this is that the paint thread has no way of knowing that the canvas has been deleted and will continue to use the canvas even after it is dead and gone to the great bit bucket in the sky.

You can use TGIFImage.PaintStop to stop all paint threads or TGIFImage.StopDraw to stop only the main paint thread. The main paint thread is the one that are used when you display a GIF with a TImage component or by using TCanvas.Draw and TCanvas.StretchDraw.


Question I've just installed TGIFImage but I can't find it anywhere on the component palette. Where is it?
Answer TGIFImage isn't a component and as such won't show up on the component palette. Only classes that are derived from TComponent are real components. I often refer to TGIFImage as a component but this is only because it's easier for people to understand.

TGIFImage is just like TBitmap, TStringList, TIniFile etc; It's a class that you only use at run-time.


Question What do I need to do in order to use GIFs with the TImage component?
Answer
Delphi Delphi
The only thing you need to do, is to add the "gifimage" unit to a uses clause anywhere in your project:
          Uses
            GifImage, Windows, Messages, SysUtils, Classes... etc.

 
C++ Builder C++ Builder
The only thing you need to do, is to include the "gifimage" module in your project. To include the gifimage module in your project, you can either use the project manager or add the following line to your project source file:
          USEUNIT("GIFImage");

 
When you do this, TGIFImage will automagically register itself with the TPicture class in the initialization section of the gifimage unit.
TPicture is the class that TImage uses to support different graphic formats.

Note that in order to load and display GIFs at design time, you have to add gifimage.pas to a designtime package or install it in the VCL library (Delphi 2). See the Installation instructions for details.


Question When I load a form with a TImage that contains a GIF I get a an error message saying something like "Out of memory while expanding stream". I have plenty of memory in my system. What's wrong?
Answer You probably have another GIF library installed.
The error is often caused by one GIF library attempting to load an image stored in a form (or some other stream) by another GIF library.
Read the "Before you start" section of the Installation instructions for a solution.

Question How do I prevent a GIF from animating when I load it into a TImage component?
Answer You can do this by setting the default GIF options prior to loading the GIF:
Delphi Delphi
        Exclude(GIFImageDefaultDrawOptions, goAnimate);
        Image1.Picture.LoadFromFile(Filename);
        Include(GIFImageDefaultDrawOptions, goAnimate);

 
C++ Builder C++ Builder
        GIFImageDefaultDrawOptions >> goAnimate;
        Image1->Picture->LoadFromFile(Filename);
        GIFImageDefaultDrawOptions << goAnimate;

Question I'm drawing a transparent animated GIF on top of another image but when I change the background image, the area covered by the animated GIF still displays the old background. How do I get it to use the new background?
Answer The problem is that TGIFImage doesn't know that you have changed the background image and still has the old background in its buffers.
In order to clear TGIFImage's background buffer, you will have to restart the animation:

Delphi Delphi
        // Stop animations and clear buffers
        TGIFImage(Image1.Picture.Graphic).StopDraw;
        // Restart animation
        Image1.Invalidate;

 
C++ Builder C++ Builder
        // Stop animations and clear buffers
        static_cast(Image1->Picture->Graphic)->StopDraw();
        // Restart animation
        Image1->Invalidate();


Question How can I disable GIF animation at design time?
Answer Modify the Register procedure in gifimage.pas to include the following line:
    Exclude(GIFImageDefaultDrawOptions, goAnimate);

Question What does the warning message "Premature end of data" mean?
Answer It means that the LZW decoder ran out of data while it was decompressing the GIF file and indicates that the GIF file is either corrupt or has been truncated.
This can easily happen when you save GIFs from the internet.

Question How can I display a GIF without using the TImage component?
Answer You can use the TGIFImage.Paint method or TCanvas.Draw and TCanvas.StretchDraw.
See the Thread demo application for an example of how to use TGIFImage.Paint.

Question When will there be a version of TGIFImage for Delphi 1?
Answer There are currently no plans for a Delphi 1 version.
The reason is that it probably would require a major rewrite and generally decrease the speed and integrity of the 32 bit version of the library.
For a list of GIF libraries that support Delphi 1, you can check out some of the other libraries.

Question When will there be a version of TGIFImage for C++ Builder 1?
Answer There are currently no plans for a C++ Builder 1 version.
Read this lame excuse for an explanation and then check out the competition instead.

Question I have created an animated GIF but I can't get it to loop. What's wrong?
Answer You need to add a "Netscape Loop" extension block to the first frame of your GIF. The loop block must be the first extension you define for the frame or else it will not work.
See the Animate demo for an example of how to build an animated GIF.

Question I'm displaying an animated GIF in a TImage component but the display flickers quite a bit. It looks as if the image is cleared between each frame, making it quite flashy. Is there a way to disable this?
Answer This problem is described in the List of known problems.
To avoid the flicker you must use the goDirectDraw option. See the Animate, Resource and GIF Explorer demo applications for an example of this.

Question How can I modify the speed of an animated GIF?
Answer The speed of an animated GIF is controlled by "Graphic Control Extension" (GCE) blocks that are attached to each frame of an animated GIF.
To modify the speed you must adjust the Delay value specified in the GCE blocks.
If you just wish to modify the animations speed temporarily at run time, you can use the TGIFImage.AnimationSpeed property. See the GIF Explorer demo application for an example of this.

Question When I open some of the demo applications in Delphi (or C++ Builder) I get a lot of warning messages saying something like:
    Error reading FormMain.Font.CharSet: Property does not exist
Answer You can safely ignore these messages.
The reason you are getting them is that the forms were saved with a newer version of Delphi or C++ Builder than the one you are using. If you open all the forms in the IDE and then save them, you will not get the warning messages the next time you open the forms.

Question How do I make a transparent GIF?
Answer Try something like this:
    var
      GIF: TGIFImage;
      Ext: TGIFGraphicControlExtension;
    begin
      GIF := TGIFImage.Create;
      try
        // Convert bitmap to GIF
        GIF.Assign(Bitmap);
        // Create an extension to set the transparency flag
        Ext := TGIFGraphicControlExtension.Create(GIF.Images[0]);
        Ext.Transparent := True;
        // Set transparent color to lower left pixel color
        Ext.TransparentColorIndex :=
          GIF.Images[0].ActiveColorMap[GIF.Images[0].Pixels[0, GIF.Height-1]];
        GIF.Images[0].Extensions.Add(Ext);
        // Do something with the GIF here...
        ...
      finally
        GIF.Free;
      end;
    end;
You should also check out the Animate demo application for an example of this.

Question Isn't there an easier way to make a transparent GIF?
Answer Yes of course there is:
    var
      GIF: TGIFImage;
    begin
      GIF := TGIFImage.Create;
      try
        // Make bitmap transparent
        Bitmap.Transparent := True;
        // Convert bitmap to GIF
        GIF.Assign(Bitmap);
        // Do something with the GIF here...
        ...
      finally
        GIF.Free;
      end;
    end;

Question Is there an ActiveX or DLL version of TGIFImage?
Answer No.

Question My GIFs looks strange in PhotoShop, but displays correctly in other applications.
Answer This is a bug in PhotoShop.
PhotoShop is unable to handle local color maps (common in animated GIFs) and only supports GIFs with local color maps. The TGIFImage.OptimizeColorMap method can be used to convert local color maps to a single global color map.

Question How can I force a GIF to use 8 bits per pixel?
Answer Although it is generally better to use as few bits per pixel as possible (TGIFImage takes care of this for you) to minimize the size of the GIF, some applications are not able to read GIFs with less than 8 bits per pixel.
The following procedure forces a GIF to use 8 bits per pixel by filling up the color map:
    procedure Force8BitGIF(GIF: TGIFImage);
    begin
      while (GIF.Image[0].ActiveColorMap.Count < 256) do
        GIF.Image[0].ActiveColorMap.Add(TColor(0));
    end;

Question How can I display/load/save GIFs with the TDBImage component?
Answer The TDBImage component only supports the BMP format (TBitmap), so it cannot be used to display GIFs.
In order to store GIFs in a database you must use BLOB fields and manually read and write the GIFs from and to the BLOB fields.
The following two procedures can be used to save and load GIFs to and from a BLOB field:
    procedure SaveToField(FField:TBlobField; GIF:TGIFImage);
    var
      Stream: TBlobStream;
    begin
      Stream := TBlobStream.Create(FField, bmWrite);
      try
        GIF.SaveToStream(Stream);
      finally
        Stream.Free;
      end;
    end;
    
    procedure LoadFromField(FField:TBlobField; GIF: TGIFImage);
    var
      Stream: TBlobStream;
    begin
      Stream := TBlobStream.Create(FField, bmRead);
      try
        GIF.LoadFromStream(Stream);
      finally
        Stream.Free;
      end;
    end;

Question BoundsChecker (or MemorySleuth, MemProof etc) shows that TGIFImage is leaking a bitmap handle. What should I do?
Answer This is probably a "controlled" leak if it is only a single bitmap handle. It is supposed to be there, don't worry about it.
In order to work around a serios resource leak in Delphi 3, TGIFImage leaks a single bitmap handle on purpose. This shouldn't be a problem since the bitmap handle is freed when you application exits.

Question I'm displaying 10 animated GIFs on my form and they just take forever to display on the first run through the animation. What's wrong?
Answer You must be running Windows 95 or 98.
TGIFImage uses threads to render GIFs into bitmaps, and Windows 95 and 98 does a very poor job of scheduling multiple threads.
During the first run through an animation, the GIF is converted (rendered) to bitmaps and compared to just drawing the GIF, this process is very processor intensive. This is why it is only the first run that is slow. Your machine can probably easily handle the load, but Windows chokes on the combination of multiple threads and high processor utilization.
Unfortunately there isn't any easy solution to this problem at the moment. If possible, reduce the size and number of GIFs you are displaying simultaneously.
Windows NT haven't got this problem.

Question My application (or even Windows) crashes when I'm displaying a lot of animated GIFs at the same time. Is this a bug?
Answer Again, you must be running Windows 95 or 98.
Animated GIFs use a lot of GDI resources and Windows 95 and 98 haven't got a lot of those. If you are running other resource hungry aplications at the same time (like Outlook or Word), the situation is even worse.
Each GIF uses at least 4 bitmaps plus 2 bitmaps per frame (1 if the frame isn't transparent) and 2 palettes plus 1 palette per frame. Is you are displaying many transparent GIFs with a lot of frames in each, you can easily consume all your systems GDI resources.
There isn't any easy solution to this problem either. Try reducing the number of GIFs or at least the number of frames in each GIF.
Windows NT haven't got this problem either.

Question I have written a commercial image processing library and wish to use some of TGIFImage's routines in it.
Am I allowed to do this?
Answer No. The TGIFImage conditions of use prohibits the use of TGIFImage, or parts of it, in commercial development libraries.
If you wish to use TGIFImage in a development library (or component), your library must be released as freeware.

Question I wish to use TGIFImage in a shareware image viewer.
Am I allowed to do this?
Answer Sure, no problem.
There are no restrictions on the use of TGIFImage in end-user applications.

Question What was used to create the TGIFImage on-line help?
Answer Time2Help.
http://www.time2help.com
Without Time2Help, the TGIFImage on-line help would never have become a reality.

Question What Installation System was used to create the TGIFImage installer?
Answer Wise InstallMaster version 7.
Great product, incompetent support, lousy upgrade policy.
http://www.wisesolutions.com
Unfortunately I cannot wholeheartedly recommend Wise Install because of their mediocre support and upgrade history. I suggest you check the Wise newsgroups for more info.

 


Copyright © 1999 Anders Melander. All rights reserved.