finally MemStream.Free; jpg.Free; AFileStream.Free; end; FileStreamSize:=-1; AFileStream:=TFileStream.Create('temp.jpg', fmCreate);