Forum
Grundkurs
»Introduktion
»Snabbguide
»Komponenter
»Händelser
»Strängar
»Räkna med Delphi »Egna
typer
»Selektion
»Iteration
»Menyer
»Funktioner
»Arraystrukturer
Tips & Tricks
»Nya tips
»Blandat
»Databaser
»Filer
»Forms
»Grafik
»Internet
»Komponenter
»Matematik
»Multimedia
»Objekt/ActiveX
»Skrivare
»Strängar
»System
»Mest lästa tips
Artiklar
»Delphi och ADO
»Bygga en DLL
»Skapa en enkel rapport
»Hantera registret
»Enheter, units
»Klassen TCanvas
»Använd LookUp Controls
Nya
tips
Lägg
till tips
Delphilänkar
Gästbok
|
|
|
|
Ladda en JPEG-bild från internet
|
Kategori: Internet
Inlagt: 2005-05-21
Läst: 1460
Inlagt av: Staffan Berg
|
Beskrivning |
Ladda en JPEG-bild från internet med hjälp av detta exempel. Vilka komponenter som krävs framgår av uses-listan.
|
Kod |
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP,jpeg, ComCtrls, IdAntiFreezeBase, IdAntiFreeze; type TForm1 = class(TForm) Client: TIdHTTP; bGetImage: TButton; ImageFromNet: TImage; IdAntiFreeze1: TIdAntiFreeze; ProgressBar: TProgressBar; Label1: TLabel; procedure bGetImageClick(Sender: TObject); procedure ClientWorkBegin(Sender: TObject; AWorkMode: TWorkMode; const AWorkCountMax: Integer); procedure ClientWork(Sender: TObject; AWorkMode: TWorkMode; const AWorkCount: Integer); procedure ClientWorkEnd(Sender: TObject; AWorkMode: TWorkMode); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.bGetImageClick(Sender: TObject); var imagestream : TStringSTream; jpg : TJPEGIMAGE; begin Label1.Caption := ''; ImageFromNet.Picture := nil; imagestream := TStringStream.Create(''); //this will hold the http stream jpg := TJPEGIMAGE.Create; try Client.Get('http://www.fuzzydizzie.com/sb.jpg',imagestream); //get the image imagestream.Seek(0,sofrombeginning); //go to the beginning of the stream jpg.LoadFromStream(imagestream); //this will load the stream into the JPEG object ImageFromNet.Picture.Assign(jpg); //Finally load the jpeg .. :) except ShowMessage('An error occured while loading the jpeg from the NET'); end; jpg.Free; imagestream.Free; end; procedure TForm1.ClientWorkBegin(Sender: TObject; AWorkMode: TWorkMode; const AWorkCountMax: Integer); begin ProgressBar.Max := AWorkCountMax; ProgressBar.Position := 0; end; procedure TForm1.ClientWork(Sender: TObject; AWorkMode: TWorkMode; const AWorkCount: Integer); begin ProgressBar.Position := AWorkCount; end; procedure TForm1.ClientWorkEnd(Sender: TObject; AWorkMode: TWorkMode); begin Label1.Caption := 'Image received !' end; end.
|
|
|