Re: IdHTTP and AXIX IP Camera

Giganews Newsgroups
Subject: Re: IdHTTP and AXIX IP Camera
Posted by:  Remy Lebeau \(Indy Team\) (re…
Date: Mon, 28 Mar 2011

"Quinn" <qui…> wrote in message

> Now I cannot get images at all.
> This code used to work.

You should never have been downloading the data as a String and then using a
TStringStream to load it.  You are lucky that ever worked at all.  This is
especially important to recognize because in the latest version of Indy, the
String based versions of Get() and Post() perform character decoding on the
bytes received (as does TStringStream in D2009+), which is likely corrupting
your image data now.  Older pre-Unicode versions of Indy simply returned an
AnsiString containing the raw bytes, but that is no longer the case.  A
String is a very bad choice to use as a binary container.  You need to
download and load the raw image data as-is, such as with a TMemoryStream (in
any Indy version), eg:

IdHTTP := TIdHTTP.Create( nil );
  IdHTTP.Request.BasicAuthentication := True;
  IdHTTP.Request.Username := sUSER;
  IdHTTP.Request.Password := sPASS;

  imageStream := TMemoryStream.Create;
    IdHTTP.Get( 'http://' + sIP + sCMD, imageStream);
    imageStream.Position := 0;
    JpgImage.LoadFromStream( imageStream );

Remy Lebeau (TeamB)


In response to

IdHTTP and AXIX IP Camera posted by Quinn on Mon, 28 Mar 2011