Пример #1
0
 public static void DownloadImageUrl(string url)
 {
     using (WebClientMia client = new WebClientMia())
     {
         string ruta = Global.DIRECTORIO_IMAGENES + @"\" + Path.GetFileName(url);
         client.Timeout = 10000;
         client.DownloadFileAsync(new Uri(url), ruta);
     }
 }
Пример #2
0
        private void BackgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            int ndx = data.IndexOf("\"ou\"", StringComparison.Ordinal);

            while (ndx >= 0)
            {
                ndx = data.IndexOf("\"", ndx + 4, StringComparison.Ordinal);
                ndx++;
                int    ndx2  = data.IndexOf("\"", ndx, StringComparison.Ordinal);
                string urlUn = data.Substring(ndx, ndx2 - ndx);
                ndx = data.IndexOf("\"ou\"", ndx2, StringComparison.Ordinal);

                try
                {
                    var webClient = new WebClientMia();
                    webClient.Headers.Add("User-Agent: Other");
                    webClient.Timeout = 10000;
                    byte[] imageBytes = webClient.DownloadData(urlUn);
                    webClient.Dispose();

                    if (imageBytes != null)
                    {
                        using (var ms = new MemoryStream(imageBytes))
                        {
                            Console.WriteLine(urlUn);
                            bmp = new Bitmap(ms);
                            if (ms != null)
                            {
                                imageList1.Images.Add(urlUn, bmp);
                                lvImagenes.Items.Add(urlUn, "", i);
                                i++;
                            }
                        }
                    }
                }
                catch (Exception we)
                {
                    Console.WriteLine("Error en imagen # " + i + ", " + we.ToString());
                    splash.Hide();
                }
                if (i == 6)
                {
                    break;
                }
            }

            lblCantidadImagenes.Text = lvImagenes.Items.Count.ToString();
            lblInfo.Visible          = false;
            timer1.Stop();
            timer1.Dispose();
            splash.Hide();
        }
Пример #3
0
        private string GetHtmlCode()
        {
            try
            {
                string url = "https://www.google.com/search?q=" + elemento + "&tbm=isch";

                var webClient = new WebClientMia();
                webClient.Headers.Add("User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko");
                webClient.Timeout = 10 * 60 * 1000;
                data = webClient.DownloadString(url);
                webClient.Dispose();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Revisa tu conexión a internet, " + ex.Message);
            }
            return(data);
        }
Пример #4
0
 public static Bitmap GetImageFromUrl(string url)
 {
     try
     {
         var webClient = new WebClientMia();
         webClient.Headers.Add("User-Agent: Other");
         webClient.Timeout = 4000;
         byte[] imageBytes = webClient.DownloadData(url);
         webClient.Dispose();
         using (var ms = new MemoryStream(imageBytes))
         {
             return(new Bitmap(ms));
         }
     }
     catch (WebException we)
     {
         Console.WriteLine(we.ToString());
     }
     return(null);
 }