Exemplo n.º 1
0
 public async Task RetrieveImage()
 {
     if (retrievingImage)
     {
         return;
     }
     retrievingImage = true;
     try
     {
         HttpHelper.TryGetImage(URL, out img);
         UpdatePreview();
         ImageUpdated?.Invoke(this);
         retrievingImage = false;
     }
     catch
     {
         ImageScraper.TryGetImage(URL, (bmp) =>
         {
             if (bmp == null)
             {
                 return;
             }
             img = bmp;
             UpdatePreview();
             ImageUpdated?.Invoke(this);
             retrievingImage = false;
         });
     }
 }
Exemplo n.º 2
0
        private async Task Scrap(int index)
        {
            SetStatus("Scraping Images...");

            Size minSize = new Size(Settings.Default.MinWidth, Settings.Default.MinHeight);

            ImageScraper.GetImageURLs(urls[index].URL, async(imgUrl, size) =>
            {
                if (imgUrl == null)
                {
                    SetStatus("Idle");
                    return;
                }
                if ((size.Width > 0 && size.Width < minSize.Width) || (size.Height > 0 && size.Height < minSize.Height))
                {
                    return;
                }
                ImageWrapper iw;
                if (!Cache.Lookup(imgUrl, out iw))
                {
                    iw = new ImageWrapper(imgUrl);
                    iw.RecommendationMade += recMade;
                    Cache.Stash(imgUrl, iw);
                }
                await iw.RetrieveLabels();
                await iw.RetrieveMatches();
                urls[index].AddChild(iw);
            });
        }
Exemplo n.º 3
0
        public static async Task GetSimilar(string[] labels, Action <string, Size> callback)
        {
            string urlQuery = HttpUtility.UrlEncode(String.Join(" ", labels));

            string url = String.Format(Settings.Default.LookupQuery, urlQuery);

            await ImageScraper.GetImageURLs(url, callback);
        }