🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.web
Article #224

Re: How to download an imagefile to my pc from the web

#224
From: Remy Lebeau (TeamB)
Date: Fri, 27 Jul 2007 22:42
57 lines
2573 bytes
"Asger Jorgensen" <Junk@Asger-P.dk> wrote in message
news:MPG.21148c4b892d11cd9897b9@newsgroups.borland.com...

> I have Indy 9 installed, but I don't have a clue
> as to how I do this.

Use the TIdHTTP component, passing the URL to its Get() method, to download
the image to a temporary file, and then you can load that into the TImage
afterwards, ie:

    AnsiString FileName = "c:\\folder\\stark.bmp";

    TFileStream *Strm = new TFileStream(FileName, fmCreate);
    try
    {
        try
        {
            IdHTTP->Get("http://asger-p.dk/stark.bmp", Strm);
        }
        __finally {
            delete Strm;
        }
        Image1->Picture->LoadFromFile(FileName);
    }
    __finally {
        DeleteFile(FileName);
    }

If you know that the image will always be a bitmap, then you can bypass the
temporary file altogether and download the image into a TMemoryStream
instead, and then load it into TBitmap for the Timage to display, ie:

    TMemoryStream *Strm = new TMemoryStream;
    try
    {
        IdHTTP->Get("http://asger-p.dk/stark.bmp", Strm);

        Strm->Position = 0;
        Image1->Picture->Bitmap->LoadFromStream(Strm);
    }
    __finally {
        delete Strm;
    }

> By the way is there a place where I can get c++ examples
> on how to use the different Indy components.

There aren't very many demos available for C++, sorry.

> I have a very good one for the TidFTP I got that a couple
> of years ago but I can't remember from where.

There are demos on both Indy's and AToZed's websites.


Gambit
Technical Details
Message-ID: <46aa755d$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nwr.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <MPG.21148c4b892d11cd9897b9@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: feeec,4df5c374fcc4d737
X-Google-Attributes: gidfeeec,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.internet.web
References: <MPG.21148c4b892d11cd9897b9@newsgroups.borland.com>
Subject: Re: How to download an imagefile to my pc from the web
Date: Fri, 27 Jul 2007 15:42:10 -0700
Lines: 59
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 75.82.252.126
Message-ID: <46aa755d$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1185576285 75.82.252.126 (27 Jul 2007 15:44:45 -0700)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nwr.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
X-Original-Bytes: 2431