Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


ID: 13313, Determining the size of a GIF file stored in a stream

by Anders Melander Email: Anonymous


Download Details
FTP  download also available
CDN Login Required to Download. (You will be redirected to the login page if you click on the Download Link)
To download this, you must have registered:
A free membership

For Delphi, Version 1.0  to 4.0 410 downloads
Copyright: No significant restrictions


Size: 762 bytes
Updated on Wed, 06 Oct 1999 00:00:00 GMT
Originally uploaded on Wed, 06 Oct 1999 00:00:00 GMT
SHA1 Hash: 1FAE4AF13F9A67F8EFF4F57E4021834A615F9D48
MD5 Hash: 31E6CEBC22326AF426F07A0282E808A8

    Explore the files in this upload

Description
This function can be used to determine the size of a GIF file stored in a stream (TStream). Handles all types of GIFs. Note that the function does not alter the stream cursor and that the GIF is assumed to start at the current position of the stream cursor. Examples of use: 1) Determine the size of a single GIF stored in a file (e.g. a GIF file).
var
  Stream: TStream;
  Size: integer;
begin
  Stream := TFileStream.Create('test.gif', fmOpenRead OR fmShareDenyWrite):
  try
    Size := GIFSize(Stream);
    ShowMessage(format(Size of GIF is %d bytes', [Size]);
  finally
    Stream.Free;
  end;
end;
2) Save two GIFs to a stream and determine their size.
var
  Buffer, Stream: TStream;
  Size: integer;
begin
  Stream := TMemoryStream.Create;
  try
    Buffer := TMemoryStream.Create;
    try
      // Load the first GIF into a memory stream...
      Buffer.LoadFromFile('first.gif');
      Buffer.Position := 0;
      // ...and save it to the stream
      Stream.CopyFrom(Buffer, Buffer.Size);

      // Load the second GIF into a memory stream...
      Buffer.LoadFromFile('first.gif');
      Buffer.Position := 0;
      // ...and save it to the stream
      Stream.CopyFrom(Buffer, Buffer.Size);
    finally
      Buffer.Free;
    end;

    // First determine the size of the first GIF...
    Stream.Position := 0;
    Size := GIFSize(Stream);
    ShowMessage(format(Size of first GIF is %d bytes', [Size]);

    // ... now that we know the size of it,
    // we can seek past the first GIF...
    Stream.Seek(Size, soFromCurrent);

    // ...and then determine the size of the second GIF
    Size := GIFSize(Stream);
    ShowMessage(format(Size of second GIF is %d bytes', [Size]);
  finally
      Stream.Free;
  end;
end;

   Latest Comments  View All Add New

Move mouse over comment to see the full text

Server Response from: ETNACDC03