Skip to content

How to download first image from google

Abdu Rafeeq

Asked Oct 3, 2019, 9:34 PM EDT3 answers
Share
LinkedInX
How to download first image from google with search any text using c# code ? Any body can help? 

3 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Željko Perić
    0
    Hello Abdu Rafeeg,
    here is sample of program code writrten  in C#
    that downloads image from Google Maps server.
    Perhaps by changing it , it can be used for solving above problem.
     
     Source code taken from : 
    1. using System;  
    2. using System.Drawing;  
    3. using System.IO;  
    4. using System.Net;  
    5. using System.Windows.Forms;  
    6.   
    7. namespace Earth_topography  
    8. {  
    9.     public partial class MainForm : Form  
    10.     {  
    11.         public MainForm()  
    12.         {  
    13.             //  
    14.             // The InitializeComponent() call is required for   
    15.             // Windows Forms designer support.  
    16.             //  
    17.             InitializeComponent();  
    18.               
    19.             //  
    20.             //   
    21.             //  
    22.         }  
    23.           
    24.         void Get_Static_Map()  
    25.         {  
    26.             //  
    27.             // Connect to Google web server and download static map  
    28.             //  
    29.               
    30.             string Google_Server_Adress = "https://maps.googleapis.com/";  
    31.               
    32.             string Google_Query =  
    33.                 "maps/api/staticmap?" +  
    34.                 "center="+Place_Location.Text+"&" +  
    35.                 "zoom="+Zoom_Level.Text.ToLower()+"&" +  
    36.                 "size=640x640&" +  
    37.                 "scale=2&" +  
    38.                 "maptype="+Map_Type.Text.ToLower().Replace(" map","")+"&" +  
    39.                 "format=jpg&" +  
    40.                 "key=HERE-ENTER-USER-KEY";  
    41.               
    42.             // New bitmap for storing map  
    43.             Bitmap Map_Data;  
    44.               
    45.             // Forms HTTP request  
    46.             HttpWebRequest query = (HttpWebRequest)   
    47.                 WebRequest.Create(Google_Server_Adress + Google_Query);  
    48.               
    49.             // Connect to the server and make request for informations  
    50.             // Declaration of a variable "response", type of HttpWebResponse  
    51.             // must be derived from HttpWebRequest.GetResponse () instance  
    52.             HttpWebResponse response = (HttpWebResponse) query.GetResponse();  
    53.                           
    54.             // Create a variable "data", type of Stream and  
    55.             // transfers the requested data from the  
    56.             // instance of variable "response" type of Stream  
    57.             Stream data = response.GetResponseStream();  
    58.               
    59.             // Read all the data and transfer them to the variable 'Map_data'  
    60.             Map_Data = new Bitmap(data);  
    61.               
    62.             // Closes and frees up all resources  
    63.             // that occupies the variable 'data'  
    64.             data.Close ();  
    65.             data.Dispose();  
    66.               
    67.             // Closes and frees up resources that occupies the variable   
    68.             // 'response'.  
    69.             // Frees connection to the Internet for reuse  
    70.             response.Close ();  
    71.               
    72.             // Show image  
    73.             Map.Image = Map_Data;  
    74.                           
    75.             //  
    76.             //  
    77.             //  
    78.         }  
    79.           
    80.         void Get_Map_Click(object sender, EventArgs e)  
    81.         {  
    82.             //  
    83.             // Call Get_Map buton event handler  
    84.             //  
    85.               
    86.             Get_Static_Map();  
    87.         }  
    88.           
    89.         void Terrain_Click(object sender, EventArgs e)  
    90.         {  
    91.             MessageBox.Show(" This option is in developing fase. ",  
    92.                             " Notice ",   
    93.                             MessageBoxButtons.OK,  
    94.                             MessageBoxIcon.Information );  
    95.         }  
    96.     }  
    97. } 
     Notice:
     Above program do not work, if You do not have correct user key, for Google Maps Platform.
     
     All the best,
     Željko Peric
    0
  • 0
    Dear sir,
     
    i want download  google images not  google map image. 
     
     
    for eg:
    0
  • Željko Perić
    0
    It is so not simple,
     
    First You need to connect to Google server and make a search request for "nokia 32".
     
    Google_Server_Address = "https://www.google.com/"
     
    Google_Query = "search?q=nokia+32"
     
    Form and send  HTTP request.
     
    When server sends response,
    it will contain HTML code of a first found web page.
    Set response data to variable type of string.
     
    Now, You need to search trough response data
    and find URL adress of a wanted image.
     
    Send another HTTP request to Google server,
    using found URL adress,
    and server will send response containing data of wanted image.
     
    Proposed program code for downloading images from Google maps server is good for that.
     
    You only need to write program code for the first part, sending search request,
    and searching trough response string for image url address.
     
    All the best,
    Željko Peric
    0