Results 1 to 10 of 16

Thread: TJPEGImage.SaveToStream problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    15 years later and I realise that my code above has an issue with loading extra data into the jpeg if the stream contains other data after the jpeg. This can cause an out of memory error if the stream is large. Fixed version is below and avoids this by copying to a new stream containing just the jpeg data.

    procedure JPegLoadFromStream(AJPG : TJPegImage ; AStream : TStream);
    Var
    LEnd : Int64;
    LMStream : TMemoryStream;
    begin
    // load the jpeg end position
    AStream.Read(LEnd, 8 );

    // Load into temporary stream as TJPeg.LoadFromStream will load to the end
    LMStream := TMemoryStream.Create;
    LMStream.CopyFrom(AStream, LEnd - AStream.Position);
    LMStream.Seek(0, soFromBeginning);

    // load the jpeg
    AJPG.LoadFromStream(LMStream);

    LMStream.Free;
    end;
    Last edited by peterbone; 29-01-2020 at 03:46 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •