Unable to save image in Gif lazarus / 39-Graphics ---------------------------------------------------------------------- artem101 · 2021-08-13 15:42 I try to draw image and write it to GIF file. There is my sample code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);var  bitmap: TBitmap;  gif: TGIFImage;begin  bitmap := TBitmap.Create;   bitmap.Width:=100;  bitmap.Height:=100;  bitmap.Canvas.Brush.Color := clWhite;  bitmap.Canvas.FillRect(Rect(0, 0, bitmap.Width, bitmap.Height));  bitmap.Canvas.Brush.Color := clBlue;  bitmap.Canvas.Line(10, 20, 60, 90);   gif := TGIFImage.Create;  gif.Assign(bitmap);  gif.SaveToFile('d:\test.gif');  gif.Free;  bitmap.Free;end; When I run this, program fails with "Abstract method called" exception. What is wrong? Windows 7 64bit, Lazarus 1.6.0 ---------------------------------------------------------------------- winni · 2021-08-13 16:34 Hi! Searching in this forum helps. This leads you to https://forum.lazarus.freepascal.org/index.php?topic=47214.0 Winni ---------------------------------------------------------------------- artem101 · 2021-08-13 16:45 It`s a pity that Lazarus doesn`t have built-in support for writing GIFs. I will try to use additional libs. Thank you for reply. ---------------------------------------------------------------------- winni · 2021-08-13 17:46 Hi! Some remarks to GIF files: * They are "out of time" and rarely used now * Because harddisks and RAM is cheap there is no need to use only 256 colors * They are widely replaced by PNG * Even animated GIFs can be replaced by animated PNGs Perhaps this is the reason why there is no GIF-Writer in Lazarus. Another reason might be that before 2004 there was a patent on LZW compression used by GIF. But that is now history. Winni ---------------------------------------------------------------------- wp · 2021-08-13 17:50 Found this fpwritegif unit in the internet: https://www.gocher.me/FPWriteGIF ; it does not support animated gifs, but maybe this is enough for you. In order to use this unit you must register the new writer. I don't know how to hook into the existing TGifImage - but this is not necessary: simply create a new gif image class inherited from TGifImage, and this new class will use this writer unit. Put the following code into a separate unit, or put it to the top of the unit in which you want to write a gif image: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses  ..., graphics, fpimage, fpwritegif; type  TMyGifImage = class(TGifImage)  protected    class function GetWriterClass: TFPCustomImageWriterClass; override;  end;  class function TMyGifImage.GetWriterClass: TFPCustomImageWriterClass;begin  Result := TFPWriterGIF;end; In the initialization section of this unit register the new image class: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ....initialization  TPicture.RegisterFileFormat('.gif', 'gif', TMyGifImage); Simply check the attached demo. The gif writer unit seems to have an issue with memory management because the demo crashes in the local ClearMappings procedure - knowing that this could create a memory leak I simply bypassed the contents of this procedure, just to get a working example; but you are warned. ---------------------------------------------------------------------- winni · 2021-08-13 18:39 Quote from: wp on August 13, 2021, 07:50:34 pmFound this fpwritegif unit in the internet: https://www.gocher.me/FPWriteGIF; it does not support animated gifs, but maybe this is enough for you. Please exclude the seicolon from the link. Now you get 404. Winni ---------------------------------------------------------------------- MarkMLl · 2021-08-13 19:05 Quote from: winni on August 13, 2021, 07:46:43 pmSome remarks to GIF files: * They are "out of time" and rarely used now * Because harddisks and RAM is cheap there is no need to use only 256 colors * They are widely replaced by PNG * Even animated GIFs can be replaced by animated PNGs Perhaps this is the reason why there is no GIF-Writer in Lazarus. Another reason might be that before 2004 there was a patent on LZW compression used by GIF. But that is now history. I think the dominant GIF handler during Delphi's heyday was similarly constrained, so Lazarus (possibly FPC) merely inherited the same functionality if not the same code. Back in the day I used to write GIFs without compression specifically for customers whose software (e.g. based on Lotus/IBM Notes/Domino) didn't yet handle PNGs. I did need to do some bitmap creation a few months ago, I ended up creating either .bmp or .pbm (I forget) and converting to the required final format by piping through scripts. Postel's law ("Be liberal in what you accept, and conservative in what you send") suggests that it would be worth clearing this loose end up, even if it was expected to be rarely used. MarkMLl ---------------------------------------------------------------------- winni · 2021-08-13 19:59 Hi! Despite that GIFs are nearly forgotten they are still used in the animated version. Useful, nice, awful and kiddie stuff. BGRAControls  implemented the component TBGRASpriteAnimation. For animated GIFs. And The BGRAbitmapPack added in one of the last versions GIF support. If GIFs are desperatly needed you could use BGRA, Winni ---------------------------------------------------------------------- winni · 2021-08-13 20:15 Hi Simple demo with  TBGRASpriteAnimation; Cheeta is running back and forth on a form. Project attached. Winni ---------------------------------------------------------------------- Jurassic Pork · 2021-08-13 22:27 hello, to save bitmap in gif format you can use  vampyreImaging library (available on package manager). Example : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses  Imaging, ImagingTypes, ImagingClasses, ImagingComponents;         procedure TForm1.Button8Click(Sender: TObject);var  bitmap: TBitmap;  myGIF : TImagingGif;  I: LongInt;begin  bitmap := TBitmap.Create;   bitmap.Width:=100;  bitmap.Height:=100;  bitmap.Canvas.Brush.Color := clWhite;  bitmap.Canvas.FillRect(Rect(0, 0, bitmap.Width, bitmap.Height));  bitmap.Canvas.Brush.Color := clBlue;  bitmap.Canvas.Line(10, 20, 60, 90);  myGIF := TImagingGif.Create;  myGIF.Assign(Bitmap);  myGIF.SaveToFile('d:\temp\test.gif');  myGIF.Free;  bitmap.Free;end;   Friendly, J.P