Thread: get bitmap from image in website.

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    58

    get bitmap from image in website.

    hi,
    i need to get bitmap data from image in current website.
    after i get bitmap handle, i want to save this bitmap.
    i got some code about it in several site, but it didnt work well.
    it got bitmap handle, but it didnt work to save file because of no correct bitmap data, i guess.
    can i get snippet code to fix it?
    best wishes
    so

  2. #2
    Registered User
    Join Date
    Mar 2009
    Location
    england
    Posts
    209
    I'm not quite sure what you mean by "getting a bitmap from a current website". If you want to download and save an image from a webserver, and you know the address of the image, you could do something along these lines:

    Code:
    using System;
    using System.Net;
    using System.Drawing;
    
    namespace TestApplication
    {
        class Program
        {
            static void Main()
            {
                // example
                DownloadImageAndSave("http://www.google.co.uk/intl/en_uk/images/logo.gif", "test.gif");
            }
    
            static void DownloadImageAndSave(String image_address, String target_filename)
            {
                WebRequest request = WebRequest.Create(image_address);
                WebResponse response = request.GetResponse();
                Bitmap bitmap = new Bitmap(response.GetResponseStream());
                bitmap.Save(target_filename);
                bitmap.Dispose();
                response.Close();
            }
        }
    }
    Last edited by theoobe; 03-23-2009 at 02:48 PM. Reason: added an example

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    58
    thank u for your reply.
    as i said, i have been use code like u written.
    i tried to write your code, but i got some errors like before i saw.
    plz, see the attach screenshot.
    can u fix it to help me?
    i'm newbie in c# and my english is not so good.
    regards
    so.

  4. #4
    Registered User
    Join Date
    Apr 2008
    Posts
    58
    this is error.
    .................................................. ...................
    Server Error in '/ex1' Application.
    A generic error occurred in GDI+.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.

    Source Error:

    Line 136: WebResponse response = request.GetResponse();
    Line 137: Bitmap bitmap = new Bitmap(response.GetResponseStream());
    Line 138: bitmap.Save(target_filename);
    Line 139: bitmap.Dispose();
    Line 140: response.Close();
    .................................................. .........
    Last edited by sgh; 03-23-2009 at 10:08 PM.

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. how to convert a bitmap image to a jpg image file using C++?
    By nomer in forum Windows Programming
    Replies: 4
    Last Post: 06-04-2006, 07:40 PM
  3. OpenGL -- Bitmaps
    By HQSneaker in forum Game Programming
    Replies: 14
    Last Post: 09-06-2004, 04:04 PM
  4. How to change a mouse cursor in console mode
    By GaPe in forum Windows Programming
    Replies: 10
    Last Post: 07-03-2002, 07:42 AM
  5. texture is all white in opengl!
    By Crossbow in forum Game Programming
    Replies: 7
    Last Post: 03-31-2002, 11:54 AM