title: Load Image from Stream - range check error
body: <p>I'm trying to send a picture of a DataSnap server to the client via Stream, more trying to open the stream on the client I get the error "range check error"
  I get this image of a url and need to send to the client via stream or otherwise.</p>
  
  <pre><code>    //SERVER
  function TServerMethods1.DownloadImage(xUrlImg : String; out resp : String) : TStream;
  var
    HTTP : TIdHttp;
    Stream : TStream;
    Image : TImage;
    stemp : String;
  begin
   try
      HTTP := TIdHttp.Create(nil);
      try
        Stream := TMemoryStream.Create;
        try
          HTTP.ReadTimeout := 10000;
          HTTP.ConnectTimeout := 10000;
          HTTP.Get(xUrlImg, Stream);
          Stream.Position := 0;
  
          Image := TImage.Create(nil);
          Image.BitMap := TBitMap.Create(0, 0);
          Image.BitMap.LoadFromStream(Stream);
          sTEmp := DateTimeToStr(now).Replace('/', '').Replace(':', '') + '.jpg';
          Image.Bitmap.SaveToFile('C:\SISTEMAS\MOBILE\' + stemp);
          //Image.Free;
  
          Result := TMemoryStream.Create;
          Image.Bitmap.SaveToStream(Result);
          Result.Seek( 0, TSeekOrigin.soBeginning );
          Result.Position := 0;
          Image.Free;
          //Result.CopyFrom(Stream, 0);
          Stream.Free;
        finally
          //img := Stream;
          resp := '';
          //Stream.Free
        end
      finally
        HTTP.Free
      end;
   Except
     ON E: Exception do
       begin
         resp := 'ERRO: ' + E.Message;
       end;
   end;
  end;
  </code></pre>
  
  <p>//client</p>
  
  <pre><code>    function TFPrin.SalvaImg(URL, xNomeImg : String) : Boolean;
  var
    Stream : TStream;
    Image : TImage;
    pathImage,
    sTemp : String;
  begin
   try
    Stream := TMemoryStream.Create;
    Stream := ClientModule1.ServerMethods1Client.DownloadImage(URL, sTemp);
    Stream.Position := 0;
    if Trim(sTemp) &lt;&gt; '' then
       begin
        //Stream.Free;
        ShowMessage('Erro: ' + sTemp);
        Exit;
       end;
  
    pathImage := GetDirPlat + xNomeImg;
    Image := TImage.Create(nil);
    //Image.BitMap := TBitMap.Create(0, 0);
    Image.BitMap.LoadFromStream(Stream);  **//ERROR - RANGE CHECK ERROR**
    Image.Bitmap.SaveToFile(pathImage);
    Image.Free;
    //Stream.Free
  
   Except
    On E: Exception do
      begin
         ShowMessage('Erro gerar imagem: ' + e.Message);
      end;
   end;
  end;
  </code></pre>