/// <summary> /// do in a separate thread /// 下载缩略图线程 /// </summary> /// <param name="page"></param> /// <param name="count"></param> /// <param name="word"></param> public void PreFetchPage(int page, int count, string word, ImageSite site) { (new Thread(new ThreadStart(() => { try { preFetchedPage = site.GetPageString(page, count, word, proxy); prePage = page; preCount = count; preWord = word; preSite = site; List <Img> imgs = site.GetImages(preFetchedPage, proxy); //获得所有图片列表后反馈得到的数量 PreListLoaded(imgs.Count, null); if (imgs.Count < 1) { return; } SessionClient sweb = new SessionClient(); SessionHeadersCollection shc = new SessionHeadersCollection(); shc.Accept = null; shc.ContentType = SessionHeadersValue.ContentTypeAuto; shc.Add("Accept-Ranges", "bytes"); shc.Referer = site.Referer; imgs = site.FilterImg(imgs, MainWindow.MainW.MaskInt, MainWindow.MainW.MaskRes, MainWindow.MainW.LastViewed, MainWindow.MainW.MaskViewed, true, false); //预加载缩略图 foreach (HttpWebRequest req1 in imgReqs) { if (req1 != null) { req1.Abort(); } } preFetchedImg.Clear(); imgReqs.Clear(); //prefetch one by one int cacheCount = CachedImgCount < imgs.Count ? CachedImgCount : imgs.Count; for (int i = 0; i < cacheCount; i++) { WebResponse res = sweb.GetWebResponse(imgs[i].PreviewUrl, proxy, 9000, shc); System.IO.Stream str = res.GetResponseStream(); if (!preFetchedImg.ContainsKey(imgs[i].PreviewUrl)) { preFetchedImg.Add(imgs[i].PreviewUrl, MainWindow.MainW.CreateImageSrc(str)); } } } catch { //Console.WriteLine("useless"); } }))).Start(); }
/// <summary> /// 构造函数 /// </summary> /// <param name="img">图片</param> /// <param name="index">缩略图位置索引</param> /// <param name="site">图片站点</param> public ImgControl(Img img, int index, ImageSite site) { InitializeComponent(); this.site = site; Image = img; this.index = index; shc.Add("Accept-Ranges", "bytes"); shc.Accept = null; shc.Referer = site.Referer; shc.Timeout = 8000; shc.ContentType = SessionHeadersValue.ContentTypeAuto; if (img.IsViewed) { //statusBorder.Background = new SolidColorBrush(Color.FromArgb(0xCC, 0xFE, 0xE2, 0xE2)); statusBorder.Background = new SolidColorBrush(Color.FromArgb(0xEE, 0xE9, 0x93, 0xAA)); } //try //{ //string s = .Substring(img.Score.IndexOf(' '), img.Score.Length - img.Score.IndexOf(' ')); //score.Text = img.Score.ToString(); //} //catch { } /* * if (!supportScore) * { * brdScr.Visibility = System.Windows.Visibility.Hidden; * }*/ //chk.Text = img.Dimension; //RenderOptions.SetBitmapScalingMode(preview, BitmapScalingMode.Fant); preview.DataContext = img; preview.SizeChanged += new SizeChangedEventHandler(preview_SizeChanged); preview.ImageFailed += new EventHandler <ExceptionRoutedEventArgs>(preview_ImageFailed); preview.MouseUp += new MouseButtonEventHandler(preview_MouseUp); statusBorder.MouseUp += new MouseButtonEventHandler(preview_MouseUp); chk.MouseUp += new MouseButtonEventHandler(preview_MouseUp); txtDesc.MouseUp += new MouseButtonEventHandler(preview_MouseUp); downBtn.MouseUp += new MouseButtonEventHandler(Border_MouseUp); magBtn.MouseUp += new MouseButtonEventHandler(preview_Click); //chk.Click += chk_Checked; //ToolTip tip = preview.ToolTip as ToolTip; //tip.PlacementTarget = preview.Parent as UIElement; //TextBlock desc = (tip.Content as Border).Child as TextBlock; //下载缩略图 //DownloadImg(); if (img.DownloadDetail != null) { //need detail LayoutRoot.IsEnabled = false; //isRetrievingDetail = true; chk.Text = "信息未加载"; } else { ShowImgDetail(); } }