public static ImageSource Get(string url, out Pass p) { p = new Pass(); ImageSource ret = null; try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.ServicePoint.ConnectionLimit = 50; request.Proxy = WebRequest.DefaultWebProxy; request.UserAgent = "Opera/9.62 (Windows NT 5.1; U; en) Presto/2.1.1"; request.Timeout = 10 * 1000; request.ReadWriteTimeout = request.Timeout * 6; request.Referer = string.Format("http://maps.{0}/", GMap.NET.MapProviders.GoogleMapProvider.Instance.Server); request.KeepAlive = true; using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) { Stream responseStream = CopyStream(response.GetResponseStream()); p.srcStream = responseStream; ret = FromStream(responseStream); } } catch (Exception) { ret = null; } return ret; }
void loader_DoWork(object sender, DoWorkEventArgs e) { foreach (string panoId in listPanoIds) { //string panoId = "uyu6kayK95wR4srpxImGmA"; //0, 1 //1, 2 //2, 4 //3, 7 //4, 13 //5, 26 jumpBuffStream = new List<List<Stream>>(); string file = "Tiles\\" + zoom + "\\" + panoId + "\\img_merged.jpg"; string directory = System.IO.Path.GetDirectoryName(file); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } if (File.Exists(file)) { Stream s = File.OpenRead(file); buffStream.Add(s); } else { for (int y = 0; y < limitY; y++) { loader.ReportProgress(0, indexBuff); for (int x = 0; x < limitX; x++) { Pass p = new Pass(); Debug.WriteLine(DateTime.Now); //finds the necessary images, also saves stream to p.scrStream ImageSource src = Get("http://maps.google.com/cbk?output=tile&panoid=" + panoId + "&zoom=" + zoom + "&x=" + x + "&y=" + y, out p); if (y == limitY - 1) //crop the black part of the bottom pictures, saves space and optimizes loading src = cropImage(src, zoom == 2 ? cropHeightZoom2 : cropHeigthZoom3); p.Y = y; p.X = x; Holder holder = new Holder(); holder.index = indexBuff; holder.pass = p; if (p.X == limitX - 1 && p.Y == limitY - 1) previousJumpBuffStream = new List<List<Stream>>(jumpBuffStream); loader.ReportProgress(100, holder); } } } indexBuff++; GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); } }