Retrieve Image via Stream


thanks for this nice toolset. In the past I was using the Overbyte ICS components but want to switch to Sparkle. At present I am stuck with the following:

I try to retrieve an image from the web (e.g. and assign it to a TImage on a FireMonkey form.

My attempts via GetContentsasStream have been unsuccessful so far. Would you have some guidance or sample to show how this is done? 

Many thanks in advance

What is the code you tried?

Be aware that the stream returned by ContentAsStream does not provide a value for Size property - because it retrieves data on demand, it's a forward-only stream that you should use to retrieve chunked data, for example. You must rely only on Read method of that stream. You can also get the content as TBytes, and then transfer those bytes to the image.

A code like this works, for example:

    S := TBytesStream.Create(Resp.ContentAsBytes);

Thanks Wagner,

in the meantime I solved it based on the FillResponseBinary from the sample.

    bt := Resp.ContentAsBytes;
    ms := TMemoryStream.Create;
    bmp := TBitmap.CreateFromStream(ms);

Kind regards