ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 TImageEnView: Load animated GIF from URL
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

PeterPanino

933 Posts

Posted - Nov 12 2024 :  08:24:30  Show Profile  Reply
Please allow loading and playing an animated GIF in TImageEnView from an Internet URL (without having to use a TImageEnMView), for example:

ImageEnView1.IO.LoadFromURL('https://media.tenor.com/Sq7rY9NKKd4AAAAC/oscars-standing-ovation.gif');

Currently, I have to make cumbersome diversions to load and play an animated GIF from an Internet URL in TImageEnView:

procedure TForm1.LoadAndPlayGIFFromURL(const URL: string);
var
  HTTPClient: System.Net.HttpClient.THTTPClient;
  MemoryStream: TMemoryStream;
  TempFileName: string;
begin
  // Create a temporary file name with a .gif extension
  TempFileName := TPath.GetTempFileName + '.gif';
  CodeSite.Send('TForm1.LoadAndPlayGIFFromURL: TempFileName', TempFileName);

  // Create the HTTP client and memory stream
  HTTPClient := THTTPClient.Create;
  MemoryStream := TMemoryStream.Create;
  try
    try
      // Download the GIF data from the URL into the memory stream
      HTTPClient.Get(URL, MemoryStream);
    except
      on E: Exception do
      begin
        ShowMessage('Error downloading GIF: ' + E.Message);
        Exit;
      end;
    end;

    // Save the GIF data to the temporary file
    try
      MemoryStream.Position := 0; // Reset the stream position
      MemoryStream.SaveToFile(TempFileName);
    except
      on E: Exception do
      begin
        ShowMessage('Error saving GIF to file: ' + E.Message);
        Exit;
      end;
    end;
    // Loading the GIF directly from the stream does work, but the GIF cannot be animated:
    //ImageEnView1.IO.LoadFromStreamGIF(MemoryStream);
  finally
    HTTPClient.Free;
    MemoryStream.Free;
  end;

  var TempFileExists := FileExists(TempFileName);
  CodeSite.Send('TForm1.LoadAndPlayGIFFromURL: TempFileExists', TempFileExists);

  // Load the GIF from the temporary file into ImageEnView1
  try
    ImageEnView1.IO.LoadFromFileGIF(TempFileName);
  except
    on E: Exception do
    begin
      ShowMessage('Error loading GIF into ImageEnView1: ' + E.Message);
      Exit;
    end;
  end;

  // Start the animation
  ImageEnView1.Playing := True;

  // Save the temporary file name to the global variable for later cleanup
  FTempGIFFileName := TempFileName;
end;


To make ImageEnView1.IO.LoadFromURL animation possible, TImageEnView should store the GIF frames in memory.

Then, it should be possible to save the GIF as an animated GIF file from the TImageEnView.

xequte

38607 Posts

Posted - Nov 13 2024 :  13:36:25  Show Profile  Reply
Hi Peter

Thank you for the suggestion. We'll consider this for a future version.

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

PeterPanino

933 Posts

Posted - Nov 13 2024 :  16:54:40  Show Profile  Reply
Hi Nigel

Thanks, I'm looking forward to it.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: