locked
Download images from web in a loop RRS feed

  • Question

  • hello,

    i am trying to download images from web by loop but sometime some images are not download and image download sequence cant maintain

    is there any solution for download multiple images in a loop??

     void Release_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
            {

      var serializer = new DataContractJsonSerializer(typeof(FishtubeTV.GETSET.Offline_MyReleases_Bean.release_Result));
                    FishtubeTV.GETSET.Offline_MyReleases_Bean.release_Result Result = (FishtubeTV.GETSET.Offline_MyReleases_Bean.release_Result)serializer.ReadObject(e.Result);

    for (int i = 0; i < Result.addresses.Length; i++)
                        {
        WebClient wc = new WebClient();
     wc.OpenReadAsync(new Uri(Result.addresses[i].thumb.ToString(), UriKind.RelativeOrAbsolute), wc);
                            wc.OpenReadCompleted += new OpenReadCompletedEventHandler(wc_OpenReadCompleted_image);
       }

    }

    void wc_OpenReadCompleted_image(object sender, OpenReadCompletedEventArgs e)
            {
                if (e.Error == null && !e.Cancelled)
                {
               
                try
                {
                    byte[] imageBytes = null;
                    BitmapImage image = new BitmapImage();
                    image.SetSource(e.Result);
                    WriteableBitmap Wr_B = new WriteableBitmap(image);
                    MemoryStream ms = new MemoryStream();
                    Wr_B.SaveJpeg(ms, image.PixelWidth, image.PixelHeight, 0, 80);
                    imageBytes = ms.ToArray();

                }
                catch (Exception ex)
                {

                    Debug.WriteLine("Error image at:" + ex.ToString());
                }

            }
            }

    Saturday, August 24, 2013 5:04 AM