Les Snippets

Connexion

Récupérer un fichier Image (gif, jpg, png etc) sur internet et le mettre en mémoire

Niveau requis pour utiliser/comprendre cette source : 1 ( Débutant )
Créé le 24/03/2006 21:54:35 et initié par Nix [Liste]
Date de mise à jour : 04/05/2006 21:44:25
Vue : 21778
Catégorie(s) : Fichier / Disque, Réseau & Internet, Web, Graphique
Langages dispo pour ce code :
- VB 2005, VB.NET 1.x
- C# 1.x, C# 2.x
- Delphi .NET
- Delphi 5



Langage : VB.NET 1.x , VB 2005
Date ajout : 24/03/2006
Posté par Nix [Liste]
DateMAJ : 07/04/2006
Public Shared Function RecupFichierImageInternet(ByVal UrlFichier As String) As Image 

  Dim WebClient As New System.Net.WebClient
  Dim Img As Image 

    Try
      Dim WebResponse As System.IO.Stream
      Dim FichierDistant As String = UrlFichier 
      WebResponse = WebClient.OpenRead(FichierDistant)
      Img = Image.FromStream(WebResponse)

      WebClient.Dispose()
      WebClient = Nothing

      WebResponse.Close()
      WebResponse = Nothing
      Return Img
  Catch ex As Exception 
      WebClient.Dispose()
      WebClient = Nothing

      Return Nothing

  End Try

End Function

Langage : C# 1.x , C# 2.x
Date ajout : 24/03/2006
Posté par Charles Racaud [Liste]
DateMAJ : 24/03/2006
public System.Drawing.Image RecupFichierImageInternet(string UrlFichier)
{
  System.Net.WebClient WebClient = new System.Net.WebClient();
  System.Drawing.Image Img = null;
  try
  {
    Img = System.Drawing.Image.FromStream(WebClient.OpenRead(UrlFichier));
  }
  catch { }
  
  WebClient.Dispose();
  WebClient = null;
  return Img;
}
Langage : Delphi .NET
Date ajout : 04/05/2006
Posté par marijuanalegal [Liste]
DateMAJ : 04/05/2006
function System.Drawing.Image RecupFichierImageInternet(UrlFichier:string); 
    WebClient := System.Net.WebClient.Create; 
    Img := nil; try Img := System.Drawing.Image.FromStream(WebClient.OpenRead(UrlFichier)); 
    except on System.Exception do ; 
    end; 
    WebClient.Dispose; WebClient := nil; 
    Result := Img; 
Exit; 
Langage : Delphi 5
Date ajout : 17/11/2008
Posté par cirec [Liste]

{ Ce code est compatible avec les nouvelles lib de  Delphi2009 
  et utilise Indy10 } 
Uses 
  Windows, SysUtils, Dialogs, classes,  Graphics, 
  IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,  
  IdHTTP, 
  ExtCtrls, jpeg 
  {$ifdef  ver200}, pngimage, gifimg{$endif};  
  Function LoadImageFromUrl(Const aUrl: String; Const  aImage: TImage): boolean; 
Implementation 
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;  

{ Charge une image depuis le net et l'affiche  dans un TImage 
  sans passer par le HDD } 
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; 
End. 

{  Utilisation } 
  LoadImageFromUrl('http://www.delphifr.com/gdi/c/45850.cs.jpg', image1); 


Snippets en rapport avec : Fichier, Image, Http, Web, Request



Codes sources en rapport avec : Fichier, Image, Http, Web, Request

{Visual Basic, VB6, VB.NET, VB 2005} GENERATEUR DE CAPTCHA
Ce projet permet d'apprendre à utiliser l'outil Graphics dans le but de modifier des images. Cette s...

{JAVA / J2EE} MINI SERVEUR HTTP
Première source en java. Il sagit d'un serveur HTTP qui permet au client d'avoir la possibilité d...

{Visual Basic, VB6, VB.NET, VB 2005} GADGET DIAPORAMA
Pour ceux qui n'ont pas Vista, voici le programme qu'il vous faut! Un "Gadget" qui se place en haut ...

{Visual Basic, VB6, VB.NET, VB 2005} RENOMMER FICHIERS AVEC VIEWER
Sert à trier des photos à l'aide d'un viewer,les classer, les renommer pour l'exécution d'un diapora...

{C / C++ / C++.NET} COMPARATEUR D'IMAGES DE CONSOLE MONOCHROME DE BASE ET CRÉATION D'UN FICHIER DE DIFFÉRENCE.
"Extrait de ce qui est demandé dans le cadre de ce projet: A Spécifications A.1 Entrée Le progr...

{Visual Basic, VB6, VB.NET, VB 2005} SERVEUR HTTP (FICHIERS/WEB) PARTAGEZ VOS FICHIERS
PRESENTATION RAPIDE Cette application a été concue dans le but de partager des fichiers sur interne...

{PHP} ENREGISTRER UNE IMAGE D'UN SITE DISTANT
Cette class permet d'enregistrer localement une image d'un site web. Il faut pour cela connaître l'...

{Python} SERVEUR WEB EN PYTHON.
Voila j'ai deja poster un ptit serveur en carton :( mais bon la j'ai fait quelque chose d'un peut...

{Visual Basic, VB6, VB.NET, VB 2005} YMDOWNLOADER
[vb6] Ce petit code permet de télécharger n'importe quel fichier sur le web. Il se place dans une li...

{JAVA / J2EE} EXPLORATEUR D'IMAGES
Explorateur d'images : Un composant permettant l'exploration d'un système de fichier pour consult...