Re: IdHTTP and AXIX IP Camera

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

"Quinn" <qui…@thehost.co.za> wrote in message
news:92E1DA4DD5D6E340qui…@thehost.co.za...

> 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 );
try
  IdHTTP.Request.BasicAuthentication := True;
  IdHTTP.Request.Username := sUSER;
  IdHTTP.Request.Password := sPASS;

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

--
Remy Lebeau (TeamB)

Replies

In response to

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