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;
Bookmarks