![]() |
Bitmap.LoadFromFile (internetfile)
How I make to load an Image to bitmap from Url(internet) file
example
Delphi-Quellcode:
the code above dont work, the error is:
bitmap.loadFromFile('http://www.cis.udel.edu/~mills/pic/hornrab.bmp');
Cannot open file 'c:\PathOfApplication\http://www.cis.udel.edu/~mills/pic/hornrab.bmp' so, how I make to url? Thanks a lot |
Re: Bitmap.LoadFromFile (internetfile)
The method LoadFromFile cannot load a file from the internet. You have to download the file first onto your local hard drive.
|
Re: Bitmap.LoadFromFile (internetfile)
Hi,
Thanks for reply I need another solution, I cant save files at my local drive (but stream I can) |
Re: Bitmap.LoadFromFile (internetfile)
No Problem use .LoadFromStream() instead
|
Re: Bitmap.LoadFromFile (internetfile)
Hi,
you can use the following code, which is a variation from over there: ![]()
Delphi-Quellcode:
Kind Regards
function DownloadBitmap(uri: String; bm: TBitmap): Boolean;
var s: TStream; begin Result := False; s := TMemoryStream.Create; with TIdHTTP.Create(nil) do try Get(uri, s); bm.LoadFromStream(s); Result := True; finally Free; s.Free; end; end; |
Re: Bitmap.LoadFromFile (internetfile)
I am wondering about the position property of the memory stream: LoadFromStream() will load from the actual position of the stream, but Get() will append the data or not? Is there really no need to seek to the beginning of the stream?
|
Re: Bitmap.LoadFromFile (internetfile)
Hi,
I wrote this code basead in your code:
Delphi-Quellcode:
but dont work, dont appear image in the Image1 component...
procedure TForm1.BitBtn2Click(Sender: TObject);
var s: TStream; uri:String; begin uri:='http://www.rotary.org/newsroom/downloadcenter/graphics/logos/programs/fellowships/fellowships_bmp.bmp'; s := TMemoryStream.Create; with TIdHTTP.Create(nil) do try Get(uri, s); Image1.picture.bitmap.loadFromStream(s); finally Free; s.Free; end; showMessage('.'); end; I try to save the stream 's' to file and was generated a file with 0bytes... so, Whats the problem if code above? Zitat:
|
Re: Bitmap.LoadFromFile (internetfile)
Hi,
you can try this in marabu´s code:
Delphi-Quellcode:
...
Get(uri, s); s.Position := 0; Image1.picture.bitmap.loadFromStream(s); ... |
Re: Bitmap.LoadFromFile (internetfile)
Thanks! this solve my ploblem
Thanks for all that help me :thumb: Zitat:
|
Re: Bitmap.LoadFromFile (internetfile)
Hi Thomas,
that's the point: LoadFromStream() does not reposition the stream - we have to do it explicitly. Thanks to Sko for lending a hand, too. So long. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 02:49 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz