none
Download Images from URL RRS feed

  • Question

  • I want to save images to memory 50 images

    My software processing ----

    1. Download Image from URL every 60 secs and all downloaded images have time to use 15 mins

    2. When download image done save images to memory

    3. Then show images in picturebox

    4. When user click button get next image form memory and delete old image from memory

    5. If what images not use in 15 mins auto delete from memory

    Help me ... Thank you a lot 

    Monday, April 20, 2015 4:35 PM

Answers

  • Ok chechk the below method/Events that will download 50 image and fill a List<image> object into memory, you need to add a picturebox1 and button1 to your form, I used my profile pic here on msdn the link you've send didn't work:

    //Global Variables List<Image> li = new List<Image>(); int second = 0;

    //Form Initaile public Captcha() { InitializeComponent(); } //Async download event private void ReadCallback(IAsyncResult asynchronousResult) { HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState; HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult); using (StreamReader streamReader1 = new StreamReader(response.GetResponseStream())) { li.Add(Image.FromStream(streamReader1.BaseStream)); pictureBox1.Image = li[0]; } } //Download Method for 50 images private void DownLoadImages() { try { for (int i = 0; i <= 50; i++) { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri("https://i1.social.s-msft.com/profile/u/avatar.jpg?displayname=fouad%20roumieh&size=extralarge&version=00000000-0000-0000-0000-000000000000")); request.BeginGetResponse(new AsyncCallback(ReadCallback), request); } } catch (WebException ex) { } } //Form Load private void Captcha_Load(object sender, EventArgs e) { DownLoadImages(); }

    And here on button click event we remove element and show the next one into picture box, and if used up all image we call the async download messages again to get a new list of images:

    private void button1_Click(object sender, EventArgs e) { li.RemoveAt(0); if (li.Count > 0) {

    //Show next pictureBox1.Image = li[0]; } else { DownLoadImages(); } }

    Also here a timer event I didn't enable but you can enable to check for the 15 mins and destroy the images list if passed:

    private void timer1_Tick(object sender, EventArgs e)
            {
                second = second + 1;
                int minutes = second / 60;
                if (minutes >= 15)
                {
                    li.Clear();
                    //Call downloadimages or else...
                }
            }


    Fouad Roumieh


    Monday, April 20, 2015 6:57 PM

All replies

  • Are you sure you want to keep 50 images in memory or you mean Hard Disk not memory?!

    Fouad Roumieh

    Monday, April 20, 2015 4:39 PM
  • Are you sure you want to keep 50 images in memory or you mean Hard Disk not memory?!

    Fouad Roumieh

    yes in memory because all images have a small size this is a captcha image
    Monday, April 20, 2015 4:42 PM
  • Is it windows or web app?

    Fouad Roumieh

    Monday, April 20, 2015 4:45 PM
  • Is it windows or web app?

    Fouad Roumieh

    windows appilcation
    Monday, April 20, 2015 4:48 PM
  • Do you have the URL to download these images public to use in the application? if yes and you can share please send it. Another question you saying you want to download image every 60 image explain this? What if the other images are still in memory and not used?

    Fouad Roumieh

    Monday, April 20, 2015 5:58 PM
  • Do you have the URL to download these images public to use in the application? if yes and you can share please send it. Another question you saying you want to download image every 60 image explain this? What if the other images are still in memory and not used?

    Fouad Roumieh

    http://goo.gl/owPSVv other question maybe I'm fix by myself but only save images to memory i can't
    Monday, April 20, 2015 6:41 PM
  • Ok chechk the below method/Events that will download 50 image and fill a List<image> object into memory, you need to add a picturebox1 and button1 to your form, I used my profile pic here on msdn the link you've send didn't work:

    //Global Variables List<Image> li = new List<Image>(); int second = 0;

    //Form Initaile public Captcha() { InitializeComponent(); } //Async download event private void ReadCallback(IAsyncResult asynchronousResult) { HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState; HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult); using (StreamReader streamReader1 = new StreamReader(response.GetResponseStream())) { li.Add(Image.FromStream(streamReader1.BaseStream)); pictureBox1.Image = li[0]; } } //Download Method for 50 images private void DownLoadImages() { try { for (int i = 0; i <= 50; i++) { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri("https://i1.social.s-msft.com/profile/u/avatar.jpg?displayname=fouad%20roumieh&size=extralarge&version=00000000-0000-0000-0000-000000000000")); request.BeginGetResponse(new AsyncCallback(ReadCallback), request); } } catch (WebException ex) { } } //Form Load private void Captcha_Load(object sender, EventArgs e) { DownLoadImages(); }

    And here on button click event we remove element and show the next one into picture box, and if used up all image we call the async download messages again to get a new list of images:

    private void button1_Click(object sender, EventArgs e) { li.RemoveAt(0); if (li.Count > 0) {

    //Show next pictureBox1.Image = li[0]; } else { DownLoadImages(); } }

    Also here a timer event I didn't enable but you can enable to check for the 15 mins and destroy the images list if passed:

    private void timer1_Tick(object sender, EventArgs e)
            {
                second = second + 1;
                int minutes = second / 60;
                if (minutes >= 15)
                {
                    li.Clear();
                    //Call downloadimages or else...
                }
            }


    Fouad Roumieh


    Monday, April 20, 2015 6:57 PM
  • Ok chechk the below method/Events that will download 50 image and fill a List<image> object into memory, you need to add a picturebox1 and button1 to your form, I used my profile pic here on msdn the link you've send didn't work:

    //Global Variables List<Image> li = new List<Image>(); int second = 0;

    //Form Initaile public Captcha() { InitializeComponent(); } //Async download event private void ReadCallback(IAsyncResult asynchronousResult) { HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState; HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult); using (StreamReader streamReader1 = new StreamReader(response.GetResponseStream())) { li.Add(Image.FromStream(streamReader1.BaseStream)); pictureBox1.Image = li[0]; } } //Download Method for 50 images private void DownLoadImages() { try { for (int i = 0; i <= 50; i++) { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri("https://i1.social.s-msft.com/profile/u/avatar.jpg?displayname=fouad%20roumieh&size=extralarge&version=00000000-0000-0000-0000-000000000000")); request.BeginGetResponse(new AsyncCallback(ReadCallback), request); } } catch (WebException ex) { } } //Form Load private void Captcha_Load(object sender, EventArgs e) { DownLoadImages(); }

    And here on button click event we remove element and show the next one into picture box, and if used up all image we call the async download messages again to get a new list of images:

    private void button1_Click(object sender, EventArgs e) { li.RemoveAt(0); if (li.Count > 0) {

    //Show next pictureBox1.Image = li[0]; } else { DownLoadImages(); } }

    Also here a timer event I didn't enable but you can enable to check for the 15 mins and destroy the images list if passed:

    private void timer1_Tick(object sender, EventArgs e)
            {
                second = second + 1;
                int minutes = second / 60;
                if (minutes >= 15)
                {
                    li.Clear();
                    //Call downloadimages or else...
                }
            }


    Fouad Roumieh


    Thank you so much i will try this
    Monday, April 20, 2015 7:08 PM
  • Ok let me know if you need more help on this, below is a screen shot to confirm downloading my avatar image here on msdn using the code above:


    Fouad Roumieh

    Monday, April 20, 2015 7:13 PM
  • Ok let me know if you need more help on this, below is a screen shot to confirm downloading my avatar image here on msdn using the code above:


    Fouad Roumieh

    I can use WebClient method ? for this use httpwebrequest 

    this is my code

    WebClient wClient = new WebClient();
                    wClient.Headers.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
                    wClient.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36");
                    wClient.Headers.Add("Accept-Encoding", "gzip, deflate, sdch");
                    wClient.Headers.Add("Accept-Language", "en-US,en;q=0.8");
                    byte[] ImageInBytes = wClient.DownloadData("http://bbs2.pramool.com/webboard/checksum/index6_2.php?imgnum=X00000");
                    MemoryStream ImageStream = new MemoryStream(ImageInBytes);

    applied for me pls

    Thursday, April 23, 2015 1:50 PM