Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   Delphi Bitmap.LoadFromFile (internetfile) (https://www.delphipraxis.net/83961-bitmap-loadfromfile-internetfile.html)

mr_fahrrad 9. Jan 2007 11:18


Bitmap.LoadFromFile (internetfile)
 
How I make to load an Image to bitmap from Url(internet) file

example
Delphi-Quellcode:
bitmap.loadFromFile('http://www.cis.udel.edu/~mills/pic/hornrab.bmp');
the code above dont work, the error is:
Cannot open file 'c:\PathOfApplication\http://www.cis.udel.edu/~mills/pic/hornrab.bmp'

so, how I make to url?

Thanks a lot

Luckie 9. Jan 2007 11:22

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.

mr_fahrrad 9. Jan 2007 11:24

Re: Bitmap.LoadFromFile (internetfile)
 
Hi,

Thanks for reply

I need another solution, I cant save files at my local drive (but stream I can)

mkinzler 9. Jan 2007 11:32

Re: Bitmap.LoadFromFile (internetfile)
 
No Problem use .LoadFromStream() instead

marabu 9. Jan 2007 11:35

Re: Bitmap.LoadFromFile (internetfile)
 
Hi,

you can use the following code, which is a variation from over there: klick

Delphi-Quellcode:
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;
Kind Regards

Muetze1 9. Jan 2007 12:08

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?

mr_fahrrad 9. Jan 2007 12:19

Re: Bitmap.LoadFromFile (internetfile)
 
Hi,

I wrote this code basead in your code:

Delphi-Quellcode:
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;
but dont work, dont appear image in the Image1 component...

I try to save the stream 's' to file and was generated a file with 0bytes...

so, Whats the problem if code above?


Zitat:

Zitat von marabu
Hi,

you can use the following code, which is a variation from over there: klick

Delphi-Quellcode:
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;
Kind Regards


Sko 9. Jan 2007 12:24

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);
...

mr_fahrrad 9. Jan 2007 12:28

Re: Bitmap.LoadFromFile (internetfile)
 
Thanks! this solve my ploblem

Thanks for all that help me :thumb:

Zitat:

Zitat von Sko
Hi,

you can try this in marabu´s code:
Delphi-Quellcode:
...
  Get(uri, s);
  s.Position := 0;
  Image1.picture.bitmap.loadFromStream(s);
...


marabu 9. Jan 2007 12:35

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.

Muetze1 9. Jan 2007 19:18

Re: Bitmap.LoadFromFile (internetfile)
 
Zitat:

Zitat von marabu
that's the point: LoadFromStream() does not reposition the stream - we have to do it explicitly.

I know that and that's why I was wondering about your code example. Because of this, I asked. I wrote it above, that the LoadFromStream will load from the actual position... :gruebel:

marabu 9. Jan 2007 20:04

Re: Bitmap.LoadFromFile (internetfile)
 
Hallo Thomas,

jeder kann lesen, dass du in Beitrag #6 einen Fehler in meinem Code entdeckt hast - noch einmal vielen Dank dafür. Wenn du denkst, dass ich deinen Beitrag nicht ausreichend gewürdigt habe, dann tut mir das leid. Es kann nur an meinem schlechten Englisch liegen.

Freundliche Grüße

Muetze1 9. Jan 2007 20:24

Re: Bitmap.LoadFromFile (internetfile)
 
Nein, so war das überhaupt nicht gemeint - ich hatte deinen letzten englishen Beitrag falsch verstanden. Alles andere interessiert mich nicht.


Alle Zeitangaben in WEZ +1. Es ist jetzt 14:33 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