You can use this function (compiled and tested using Delphi 2010) to download a file over HTTP and store it in a TBitMap. It'll read all file types that have a registered support in Delphi's TGraphic hiearachy, and will auto-detect BMP, GIF, JPG and PNG file formats:
USES Graphics, IdHTTP, PngImage, jpeg, GIFImg;
FUNCTION DownloadImage(CONST URL : STRING ; ImageType : TGraphicClass = NIL) : TBitMap;
VAR
HTTP : TIdHttp;
S : TStream;
IMG : TGraphic;
STR : AnsiString;
BEGIN
HTTP:=TIdHttp.Create(NIL);
TRY
S:=TMemoryStream.Create;
TRY
HTTP.Get(URL,S);
IF NOT Assigned(ImageType) THEN BEGIN
S.Position:=0;
SetLength(STR,5);
S.Read(STR[1],LENGTH(STR));
IF COPY(STR,1,2)='BM' THEN
ImageType:=TBitMap
ELSE IF COPY(STR,1,3)='GIF' THEN
ImageType:=TGIFImage
ELSE IF COPY(STR,2,3)='PNG' THEN
ImageType:=TPngImage
ELSE IF (ORD(STR[1])=$FF) AND (ORD(STR[2])=$D8) THEN
ImageType:=TJPEGImage
END;
IF NOT Assigned(ImageType) THEN RAISE EInvalidImage.Create('Unrecognized file format!');
IMG:=ImageType.Create;
TRY
S.Position:=0;
IMG.LoadFromStream(S);
Result:=TBitMap.Create;
TRY
Result.Assign(IMG)
EXCEPT
Result.Free;
RAISE
END
FINALLY
IMG.Free
END
FINALLY
S.Free
END
FINALLY
HTTP.Free
END
END;
If you already know the file type, you can specify it as the 2nd parameter as either TGifImage, TPngImage, TJPegImage or TBitMap. If not, the routine will try to auto-detect it among these four types. If you use a custom-graphic type, you'll need to specify it as the 2nd parameter or update the auto-detection logic to detect it.
So, if you want to use it to display a downloaded image in a TImage without saving it to disc, you can use it thus:
VAR
BMP : TBitMap;
BEGIN
BMP:=DownloadImage('http://domain.com/image.jpg');
TRY
Image1.Picture.Assign(BMP)
FINALLY
BMP.Free
END
END;