How can I show an image in a desktop using a html tag ?

Hi,

I have a html tag like this:

<img src="http://hostname/image.bmp" border="0">

How can i show this image in a desktop application?

Thanks.

faustomenAsked:
Who is Participating?
 
mocartsConnect With a Mentor Commented:
sorry, didn't provide you with code which loads image into TImage component... :)

uses IdHttp, Jpeg;

procedure TForm1.Button1Click(Sender: TObject);
var
 fs: TMemoryStream;
 jp: TGraphic;
begin
 http := TIdHttp.Create(nil);
 fs := TMemoryStream.Create;
 try
   // downloading image into the stream
   http.Get('http://www.experts-exchange.com/v3.0/images/greyLogo.jpg', fs);
   // to load bitmap change the line below to
   // jp := TBitmap.Create;
   jp := TJpegImage.Create;
   try
     // must set to the beginning of stream
     fs.Position := 0;
     // to avoid subsequent assignments first set graphic to desired graphic
     Image1.Picture.Graphic := jp;
     // loading into the image control
     Image1.Picture.Graphic.LoadFromStream(fs);
   finally
     jp.Free;
   end;
 finally
   fs.Free;
   http.Free;
 end;
end;

note: you can download latest Indy components from http://www.indyproject.org/

wbr, mo.
0
 
j42Commented:
Hi,
ever tried this?

  WebBrobser1.Navigate('http://hostname/image.bmp');



Regards
0
 
mocartsCommented:
you can also use Indy's TIdHTTP component:

implementation

uses IdHTTP;

procedure GetURLFile(const FromURL, ToFileName: string);
var
  http: TIdHTTP;
  fs: TFileStream;
begin
  http := TIdHttp.Create(nil);
  fs := TFileStream.Create(ToFileName, fmCreate);
  try
    http.Get(FromURL, fs);
  finally
    fs.Free;
    http.Free;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  GetURLFile('http://www.experts-exchange.com/v3.0/images/greyLogo.jpg', 'D:\saved.jpg');
end;

wbr, mo.
0
 
mocartsCommented:
you can easily check image type and create apropriate object instance by checking Response's ContentType property:
...
http.Get('http://www.experts-exchange.com/v3.0/images/greyLogo.jpg', fs);
if http.Response.ContentType = 'image/jpeg' then
  jp := TJpegImage.Create
else if http.response.ContentType = 'image/bmp' then
  jp := TBitmap.Create;
...

wbr, mo.
0
 
faustomenAuthor Commented:
Ok mocarts.

Thanks again.
0
All Courses

From novice to tech pro — start learning today.