Link to home
Start Free TrialLog in
Avatar of alexiat
alexiat

asked on

JPEG SaveToStream Problem

Can anyone please tell me why this doesn't work.  As a test, after I called LoadFromFile I also loaded the image into a TImage component and it appears just fine.  MyJPEG height and width are correct.  It just doesn't load anything to stream.  Aargh!   Thanks.

var
  ms: TMemoryStream;
  MyJPEG: TJPEGImage;
begin
  ms := TMemoryStream.Create;
  try
    MyJPEG := TJPEGImage.Create;
    try
        MyJPEG.LoadFromFile('image1.jpg');
        MyJPEG.SaveToStream(ms);
        ms.Position := 0;
//ms.memory^ shows "(no value)" and if I try to LoadFromStream() into any image the stream is empty.
    finally
       MyJPEG.Free;
       end;
  finally
     ms.Free;
     end;


Avatar of Johnjces
Johnjces
Flag of United States of America image

try changing your ms.Position := 0 to:

ms..Seek(0, soFromBeginning);

Give that a try.

John
ASKER CERTIFIED SOLUTION
Avatar of 2266180
2266180
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ms.Seek(0, soFromBeginning).

I double clicked the dot... only one not ms.. but ms.

(I know you know that but I messed up so want to make certain).

John
Avatar of alexiat
alexiat

ASKER

Whew. Thanks. Who knew you couldn't trust the debugger.  I guess this means it is the 3rd party component who is trying to use the stream that is having problems with it.  I thought I was blindly missing something.