![]() ![]() |
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.
![]() |
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? | ||
![]() |
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. |
||
![]() |
Why aren't GIF files listed as a file type in my TOpenPictureDialog or TSavePictureDialog? | ||
![]() |
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.
See the Convert demo for an example of this. The GraphicExtension and GraphicFilter functions are documented in the VCL online help. |
||
![]() |
Do I need to add TGIFImage to a package before I can use it? | ||
![]() |
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). |
||
![]() |
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? | ||
![]() |
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. |
||
![]() |
I have heard that your TGIFImage is the greatest GIF component around. Is this true? | ||
![]() |
Yes, it is absolutely true. (Isn't it just great when you can write your own FAQ?) |
||
![]() |
I'm getting "Canvas does not allow drawing" exceptions and all sorts of access violations when I use TGIFImage. What am I doing wrong? | ||
![]() |
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. |
||
![]() |
I've just installed TGIFImage but I can't find it anywhere on the component palette. Where is it? | ||
![]() |
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. |
||
![]() |
What do I need to do in order to use GIFs with the TImage component? | ||
![]() |
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. |
||
![]() |
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? | ||
![]() |
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. |
||
![]() |
How do I prevent a GIF from animating when I load it into a TImage component? | ||
![]() |
You can do this by setting the default GIF options prior to loading the GIF:
|
||
![]() |
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? | ||
![]() |
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:
|
||
![]() |
How can I disable GIF animation at design time? | ||
![]() |
Modify the Register procedure in gifimage.pas to include the following line:Exclude(GIFImageDefaultDrawOptions, goAnimate); |
||
![]() |
What does the warning message "Premature end of data" mean? | ||
![]() |
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. |
||
![]() |
How can I display a GIF without using the TImage component? | ||
![]() |
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. |
||
![]() |
When will there be a version of TGIFImage for Delphi 1? | ||
![]() |
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. |
||
![]() |
When will there be a version of TGIFImage for C++ Builder 1? | ||
![]() |
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. |
||
![]() |
I have created an animated GIF but I can't get it to loop. What's wrong? | ||
![]() |
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. |
||
![]() |
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? | ||
![]() |
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. |
||
![]() |
How can I modify the speed of an animated GIF? | ||
![]() |
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. |
||
![]() |
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 |
||
![]() |
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. |
||
![]() |
How do I make a transparent GIF? | ||
![]() |
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. |
||
![]() |
Isn't there an easier way to make a transparent GIF? | ||
![]() |
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; |
||
![]() |
Is there an ActiveX or DLL version of TGIFImage? | ||
![]() |
No. | ||
![]() |
My GIFs looks strange in PhotoShop, but displays correctly in other applications. | ||
![]() |
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. |
||
![]() |
How can I force a GIF to use 8 bits per pixel? | ||
![]() |
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; |
||
![]() |
How can I display/load/save GIFs with the TDBImage component? | ||
![]() |
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; |
||
![]() |
BoundsChecker (or MemorySleuth, MemProof etc) shows that TGIFImage is leaking a bitmap handle. What should I do? | ||
![]() |
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. |
||
![]() |
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? | ||
![]() |
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. |
||
![]() |
My application (or even Windows) crashes when I'm displaying a lot of animated GIFs at the same time. Is this a bug? | ||
![]() |
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. |
||
![]() |
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? |
||
![]() |
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. |
||
![]() |
I wish to use TGIFImage in a shareware image viewer. Am I allowed to do this? |
||
![]() |
Sure, no problem. There are no restrictions on the use of TGIFImage in end-user applications. |
||
![]() |
What was used to create the TGIFImage on-line help? | ||
![]() |
Time2Help. http://www.time2help.com Without Time2Help, the TGIFImage on-line help would never have become a reality. |
||
![]() |
What Installation System was used to create the TGIFImage installer? | ||
![]() |
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. |