Thread: Download an image from a URL

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    80

    Download an image from a URL

    Hey everyone,

    I'm having problems downloading an image from in internet location.

    I've tried 2 methods:

    Code:
    request = (HttpWebRequest)WebRequest.Create(newUrl);
    request.Method = "GET";
    
    response = (HttpWebResponse)request.GetResponse();
    Stream imageStream = response.GetResponseStream();
    Bitmap bmp = new Bitmap(imageStream);
    bmp.Save(GetFileName(url));
    and

    Code:
    WebClient client = new WebClient();                                
    client.DownloadFile(newUrl, fileName);
    The first method throws an exception in the Bitmap constructor "Invalid parameter used." The second method saves the picture, put it is in the wrong format or something, because it can't be viewed, and is only 917 bytes on disk (actual image is 84000 bytes.)

    Any ideas or other methods that can be used to download images?

    Thanks!

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    PHP Code:
    System.Net.WebClient client = new System.Net.WebClient();
     
    client.DownloadFile"http://www.cprogramming.com/cprog.gif""cprog.gif"); 
    This saves the cprog image just fine. Make sure you have internet access and your connection or the server does not go down while downloading
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    80
    As it turns out, there was just something whack with the image I was trying to download. All other images worked fine. Thanks for the reply!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem reading tiff image files?
    By compz in forum C++ Programming
    Replies: 9
    Last Post: 10-30-2009, 04:17 AM
  2. image download program
    By yoda855 in forum Windows Programming
    Replies: 6
    Last Post: 06-30-2006, 11:37 AM
  3. Replies: 4
    Last Post: 03-02-2003, 09:12 AM
  4. IE 6 status bar
    By DavidP in forum Tech Board
    Replies: 15
    Last Post: 10-23-2002, 05:31 PM
  5. download free bsd image?
    By iain in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 10-11-2002, 10:10 AM