コード例 #1
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            ImageDetector id = new ImageDetector("C:\\Users\\guest1\\Downloads\\parapara[hyper].png");

            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
        }
コード例 #2
0
        private async Task <Image> DownloadImage(string url)
        {
            // special case for importing HTML command
            var index = url.IndexOf("://onemore.");

            if (index > 0)
            {
                url = url.Remove(index + 3, 8);
            }

            var client = HttpClientFactory.Create();

            try
            {
                using (var source = new CancellationTokenSource(TimeSpan.FromSeconds(10)))
                {
                    using (var response = await client.GetAsync(new Uri(url, UriKind.Absolute), source.Token))
                    {
                        if (response.IsSuccessStatusCode)
                        {
                            using (var stream = new MemoryStream())
                            {
                                await response.Content.CopyToAsync(stream);

                                var detector = new ImageDetector();
                                if (detector.GetSignature(stream) != ImageSignature.Unknown)
                                {
                                    try
                                    {
                                        return(new Bitmap(Image.FromStream(stream)));
                                    }
                                    catch
                                    {
                                        logger.WriteLine($"{url} does not appear to be an image");
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (TaskCanceledException exc)
            {
                logger.WriteLine("timeout fetching image", exc);
            }
            catch (Exception exc)
            {
                logger.WriteLine("error fetching image", exc);
            }

            return(null);
        }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: WalrusQ/CouplingAlturos
 private void btnOpen_Click(object sender, EventArgs e)
 {
     using (var ofd = new OpenFileDialog()
     {
         Filter = @"Image files(*.png; *.jpg; *.jpeg *.bmp | *.png; *.jpg; *.jpeg *.bmp"
     })
     {
         if (ofd.ShowDialog() == DialogResult.OK)
         {
             picBx.Image = Image.FromFile(ofd.FileName);
             RecognitionOutput(ImageDetector.Process(picBx.Image), ofd.SafeFileName);
             OpenPhotoTxtBx.Text = ofd.FileName;
         }
     }
 }