1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
unit Unit6;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, DBCtrls, DB, DBAccess, MyAccess, MemDS,
Grids, DBGrids,
Mask, StdCtrls,
IdBaseComponent, IdComponent, IdTCPConnection,
IdTCPClient, IdHTTP, IdAntiFreezeBase, IdAntiFreeze, jpeg, JvDBControls,
ExtDlgs, IdExplicitTLSClientServerBase, IdFTP
{$ifdef ver200}, pngimage, gifimg, JvDBControls{$endif};
Function LoadImageFromUrl(Const aUrl: String; Const aImage: TImage): boolean;
type
TForm6 = class(TForm)
MyConnection1: TMyConnection;
MyTable1: TMyTable;
MyDataSource1: TMyDataSource;
IdHTTP1: TIdHTTP;
IdAntiFreeze1: TIdAntiFreeze;
Image1: TImage;
JvDBNavigator2: TJvDBNavigator;
DBMemo1: TDBMemo;
DBEdit1: TDBEdit;
button1: TButton;
IdFTP1: TIdFTP;
Label1: TLabel;
Label2: TLabel;
procedure MyDataSource1DataChange(Sender: TObject; Field: TField);
procedure Connection;
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form6: TForm6;
implementation
{$R *.dfm}
procedure TForm6.MyDataSource1DataChange(Sender: TObject; Field: TField);
var image:string;
begin
image:='http://monsite.fr/images/'+ mytable1.Fields.FieldByName('photo').text;
LoadImageFromUrl('http://monsite.fr/images/'+ (mytable1.Fields.FieldByName('photo').text), image1);
end;
Function GetGraphicClass(Const aFileName: String): TGraphicClass;
Var aExt: String;
Begin
Result := Nil;
aExt := LowerCase(ExtractFileExt(aFileName));
If aExt = '.ico' Then
Result := TIcon
Else
If aExt = '.bmp' Then
Result := TBitmap
Else
If (aExt = '.jpg') Or (aExt = '.jpeg') Then
Result := TJPEGImage
{$ifdef ver200}
Else
If aExt = '.gif' Then
Result := TGIFImage
Else
If aExt = '.png' Then
Result := TPNGImage
{$endif};
End;
Function LoadImageFromUrl(Const aUrl: String; Const aImage: TImage): boolean;
Var
NewGraphic : TGraphic;
GraphicClass : TGraphicClass;
aStream : TMemoryStream;
Begin
Result := assigned(aImage);
If Result Then
Begin
GraphicClass := GetGraphicClass(aUrl);
If GraphicClass = Nil Then
Begin
Result := False;
Exit;
End;
NewGraphic := GraphicClass.Create;
aStream := TMemoryStream.Create;
With TIdHTTP.Create(Nil) Do
Try
Try
Get(aUrl, aStream);
aStream.Seek(0, soFromBeginning);
NewGraphic.LoadFromStream(aStream);
Except
Result := False;
End;
Finally
aImage.Picture.Graphic := NewGraphic;
NewGraphic.Free;
aStream.Free;
Free;
End;
End;
End; |
Partager