Пример #1
0
        public static string ImageSearch(string query)
        {
            GimageSearchClient gimage = new GimageSearchClient("http://ubound.hipchat.com");

            var results = gimage.Search(query, 1);
            foreach (var result in results)
            {
                return result.Url;
            }
            return string.Empty;
        }
Пример #2
0
        public static void Load()
        {
            _manhood = new ManhoodContext(DictionaryPath);
            _manhood.StringRequested += StringRequested;

            _manhood.DoFile("lib/css.mh");
            _manhood.DoFile("lib/stanman.mh");
            _manhood.DoFile("lib/wsfhpage.mh");

            _google = new GimageSearchClient("http://berkin.me");
        }
Пример #3
0
        private void selfFindPictures(String text, int minutes)
        {
            try
            {
                GimageSearchClient client = new GimageSearchClient("http://www.google.com");
                IList<IImageResult> results;
                IAsyncResult result = client.BeginSearch(text.Trim(), minutes,
                                                        ((arResult) =>
                                                        {
                                                            results = client.EndSearch(arResult);
                                                            if (results != null)
                                                            {
                                                                images.Clear();
                                                                foreach (IImageResult res in results)
                                                                {
                                                                    //images.Add(res.Url);
                                                                    var wc = new WebClient();
                                                                    Image xImage = Image.FromStream(wc.OpenRead(res.Url));
                                                                    images.Add(xImage);
                                                                    //xImage.Save("jovan");
                                                                    //this.BackgroundImage = xImage;
                                                                }

                                                            }
                                                        }),
                                                        null);
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message);
            }
            /*timer3.Enabled = true;
            timer3.Start();
            timer3.Enabled = true;*/
            toolStripStatusLabel5.Visible = true;
        }
        void hiloGoogle_DoWork(object sender, DoWorkEventArgs e)
        {
            string[] argumentos = (string[])e.Argument;
            GimageSearchClient client = new GimageSearchClient("http://www.google.com");
            IList<IImageResult> results = client.Search(argumentos[0], int.Parse(argumentos[1]));

            int cont = 1;
            foreach (IImageResult result in results)
            {
                try
                {
                    ImagenesRescatadas.Add(new Bitmap(cliente.OpenRead(result.Url)));
                }
                catch { };

                hiloGoogle.ReportProgress(cont);
                cont++;
            }
        }
Пример #5
0
        // 300x450
        public static Bitmap CreateCover(Story story, int resultTableLength, int itemCount)
        {
            try
            {
                var google = new GimageSearchClient(@"http://google.com");
                LongRandom rand = new LongRandom(story.Seed);
                Image imgMain = new Bitmap(300, 450);
                List<string> items = story.Histograph.GetMostFrequent(itemCount);

                using (Graphics g = Graphics.FromImage(imgMain))
                {
                    Color bg = Color.FromArgb(rand.Next(0, 256), rand.Next(0, 256), rand.Next(0, 256));
                    g.Clear(bg);

                    string typeFace = fontList[rand.Next(0, fontList.Length)];
                    StringFormat sf = new StringFormat();
                    sf.Alignment = StringAlignment.Center;
                    sf.LineAlignment = StringAlignment.Center;
                    Font titleFont = new Font(typeFace, 24F, FontStyle.Regular);
                    Font authorFont = new Font(typeFace, 14F, FontStyle.Regular);
                    SizeF titleSize = g.MeasureString(story.Title, titleFont, 268);
                    SizeF authorSize = g.MeasureString(story.Author, authorFont);
                    SolidBrush titleBrush = new SolidBrush(bg.GetBrightness() > 0.5 ? Color.Black : Color.White);
                    Rectangle titleBorder = new Rectangle(8, 8, 284, (int)titleSize.Height + 8);
                    RectangleF authorRect = new RectangleF(0, 442 - authorSize.Height, 300, authorSize.Height);
                    Rectangle pictureRect = new Rectangle(titleBorder.Left, titleBorder.Bottom + 8, titleBorder.Width, (int)authorRect.Top - titleBorder.Bottom - 16);

                    g.DrawString(story.Title, titleFont, titleBrush, new RectangleF(16, 16, 268, titleSize.Height), sf);
                    g.DrawRectangle(new Pen(titleBrush, 3), titleBorder);
                    g.DrawString(story.Author, authorFont, titleBrush, authorRect, sf);

                    // Draw illustration

                    g.Clip = new Region(pictureRect);

                    var bgResults = google.Search(story.Title, resultTableLength, SafeLevel.Off, ImageSize.Large, Colorization.All, ImageColor.All, ImageType.All, ImageFileType.All, "");
                    if (bgResults.Count > 0)
                    {
                        Bitmap background = (Bitmap)DownloadImageFromURL(bgResults[rand.Next(0, bgResults.Count)].Url, false);
                        if (background != null)
                        {
                            g.DrawImage(background, pictureRect);
                            background.Dispose();
                        }
                    }
                    else
                    {
                        g.Clear(Color.FromArgb(255, rand.Next(0, 256), rand.Next(0, 256), rand.Next(0, 256)));
                    }

                    foreach (string thing in items)
                    {
                        var imgResults = google.Search(thing, resultTableLength, SafeLevel.Off, ImageSize.All, Colorization.All, ImageColor.All, ImageType.All, ImageFileType.All, "");
                        Bitmap item = (Bitmap)DownloadImageFromURL(imgResults[rand.Next(0, imgResults.Count)].TbImage.Url, true);

                        int x = rand.Next(0, pictureRect.Width) + pictureRect.Left;
                        int y = rand.Next(0, pictureRect.Height) + pictureRect.Top;
                        int width = rand.Next(32, pictureRect.Width);
                        int height = rand.Next(32, pictureRect.Height);

                        g.TranslateTransform(x, y);
                        g.RotateTransform(rand.Next(0, 360));
                        g.ResetTransform();

                        g.DrawImage(item, new Rectangle(0, 0, width, height));
                        item.Dispose();
                    }
                    g.DrawRectangle(new Pen(titleBrush, 3), pictureRect);
                }
                return (Bitmap)imgMain;
            }
            catch
            {
                return null;
            }
        }
Пример #6
0
 private Results GoogleSearch(string search)
 {
     try
     {
         List<Control> images = new List<Control>();
         Thread ImageThread = new Thread(() =>
         {
             GimageSearchClient imageSearch = new GimageSearchClient("https://www.images.google.com");
             IList<IImageResult> imageResults = imageSearch.Search(search, 25);
             Parallel.ForEach(imageResults, imr =>
             {
                 try
                 {
                     PictureBox p = new PictureBox();
                     WebClient wc = new WebClient();
                     byte[] im = wc.DownloadData(imr.Url);
                     MemoryStream ms = new MemoryStream(im);
                     p.Image = Image.FromStream(ms);
                     float w = p.Image.PhysicalDimension.Width, h = p.Image.PhysicalDimension.Height;
                     while (w > 250) { w *= .8F; h *= .8F; }
                     p.Width = (int)w;
                     p.Height = (int)h;
                     p.SizeMode = PictureBoxSizeMode.StretchImage;
                     p.Click += delegate(object a, EventArgs b)
                     {
                         Process.Start(imr.Url);
                         this.Contract();
                     };
                     p.Cursor = System.Windows.Forms.Cursors.Hand;
                     images.Add(p);
                 }
                 catch (Exception e) { }
             });
             SearchResultLink link = new SearchResultLink(search, 2);
             images.Add(link);
         });
         ImageThread.Start();
         IList<IWebResult> webResults = null;
         Thread webThread = new Thread(() =>
         {
             GwebSearchClient gs = new GwebSearchClient("https://www.google.com");
             webResults = gs.Search(search, 25, "English", "Off");
         });
         webThread.Start();
         ImageThread.Join();
         webThread.Join();
         return new Results(webResults, images);
     }
     catch (Exception e) { return null; }
 }