Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Internet
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Colaboración Paypal con ClubDelphi

 
 
Herramientas Buscar en Tema Desplegado
  #5  
Antiguo 28-05-2006
Avatar de seoane
[seoane] seoane is offline
Miembro Premium
 
Registrado: feb 2004
Ubicación: A Coruña, España
Posts: 3.717
Poder: 26
seoane Va por buen camino
Bueno, yo puedo quitarte algo de trabajo:


Código Delphi [-]
uses WinInet, JPEG;

function DownloadToStream(Url: string; Stream: TStream): Boolean;
var
  hNet: HINTERNET;
  hUrl: HINTERNET;
  Buffer: array[0..10240] of Char;
  BytesRead: DWORD;
begin
  Result := FALSE;
  hNet := InternetOpen('agent', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
  if (hNet <> nil) then
  begin
    hUrl := InternetOpenUrl(hNet, PChar(Url), nil, 0,
      INTERNET_FLAG_RELOAD, 0);
    if (hUrl <> nil) then
    begin
      while (InternetReadFile(hUrl, @Buffer, sizeof(Buffer), BytesRead)) do
      begin
        if (BytesRead = 0) then
        begin
          Result := TRUE;
          break;
        end;
        Stream.WriteBuffer(Buffer,BytesRead);
      end;
      InternetCloseHandle(hUrl);
    end;
    InternetCloseHandle(hNet);
  end;
end;

function DownloadToBmp(Url: string; Bitmap: TBitmap): Boolean;
var
  Stream: TMemoryStream;
  Jpg: TJPEGImage;
begin
  Result:= FALSE;
  Stream:= TMemoryStream.Create;
  try
    try
      if DownloadToStream(Url, Stream) then
      begin
        Jpg:= TJPEGImage.Create;
        try
          Stream.Seek(0,soFromBeginning);
          Jpg.LoadFromStream(Stream);
          Bitmap.Assign(Jpg);
          Result:= TRUE;
        finally
          Jpg.Free;
        end;
      end;
    finally
      Stream.Free;
    end;
  except end;
end;

La funcion DownloadToBmp se encarga de descargar una imagen jpeg de internet y la convierte automaticamente a Bmp. Una vez que tienes el bmp ya sabras tu lo que tienes que hacer con el.

Ejemplo de como usar la funcion:
Código Delphi [-]
var
  Bitmap: TBitmap;
begin
  Bitmap:= TBitmap.Create;
  try
    if DownloadToBmp('http://www.clubdelphi.com/images/clubdelphi.jpg', Bitmap) then
    begin
      // Aqui usa el bitmap para lo que quieras, yo por ejemplo lo guardo
      Bitmap.SaveToFile('c:\prueba.bmp');
    end;
  finally
    Bitmap.Free;
  end;
end;
Responder Con Cita
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Proyecto Nuevo - 1.4 MB Patricio Varios 5 16-12-2005 12:20:36
Evaluar un Proyecto Migpal Debates 2 24-11-2005 13:23:05
Incluir dcu en proyecto davezf Varios 3 27-07-2005 17:19:04
Proyecto MDI? danytorres Varios 2 29-10-2003 15:52:25
Imagenes del proyecto lafirma OOP 6 04-06-2003 03:20:52


La franja horaria es GMT +2. Ahora son las 20:01:51.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi