コード例 #1
0
        private async void button1_Click(object sender, EventArgs e)
        {
            openFileDialog1.ShowDialog();
            string filename = openFileDialog1.FileName;

            if (filename != "")
            {
                richTextBox1.Clear();
                richTextBox1.Focus();
                richTextBox1.Text = "Status: Uploading...";
                lblPath.Text      = filename;
                button1.Enabled   = false;
                // button2.Enabled = false;
                Bitmap bmp          = new Bitmap(openFileDialog1.FileName);
                bool   imageFlipped = false;
                foreach (var p in bmp.PropertyItems)
                {
                    if (p.Id == 274)
                    {
                        var Orientation = (int)p.Value[0];
                        if (Orientation == 6)
                        {
                            bmp.RotateFlip(RotateFlipType.Rotate90FlipNone);
                            imageFlipped = true;
                        }
                        if (Orientation == 7)
                        {
                            bmp.RotateFlip(RotateFlipType.Rotate180FlipNone);
                            imageFlipped = true;
                        }
                        if (Orientation == 8)
                        {
                            bmp.RotateFlip(RotateFlipType.Rotate270FlipNone);
                            imageFlipped = true;
                        }
                        break;
                    }
                }
                if (imageFlipped)
                {
                    if (Path.GetFileName(openFileDialog1.FileName).ToLower().EndsWith(".jpg"))
                    {
                        bmp.Save(Path.GetDirectoryName(openFileDialog1.FileName) + "\\Temp" + Path.GetFileName(openFileDialog1.FileName), System.Drawing.Imaging.ImageFormat.Jpeg);
                    }
                    else if (Path.GetFileName(openFileDialog1.FileName).ToLower().EndsWith(".png"))
                    {
                        bmp.Save(Path.GetDirectoryName(openFileDialog1.FileName) + "\\Temp" + Path.GetFileName(openFileDialog1.FileName), System.Drawing.Imaging.ImageFormat.Png);
                    }
                    else if (Path.GetFileName(openFileDialog1.FileName).ToLower().EndsWith(".gif"))
                    {
                        bmp.Save(Path.GetDirectoryName(openFileDialog1.FileName) + "\\Temp" + Path.GetFileName(openFileDialog1.FileName), System.Drawing.Imaging.ImageFormat.Gif);
                    }
                    else if (Path.GetFileName(openFileDialog1.FileName).ToLower().EndsWith(".bmp"))
                    {
                        bmp.Save(Path.GetDirectoryName(openFileDialog1.FileName) + "\\Temp" + Path.GetFileName(openFileDialog1.FileName), System.Drawing.Imaging.ImageFormat.Bmp);
                    }
                }
                Account    acc          = new Account("eyepower", "<API_KEY>", "<API_SECRET>");
                Cloudinary cloud        = new Cloudinary(acc);
                var        uploadResult = new ImageUploadResult();
                string     imgURI       = "";
                try
                {
                    if (imageFlipped)
                    {
                        uploadResult = await cloud.UploadAsync(new ImageUploadParams { File = new FileDescription(Path.GetDirectoryName(openFileDialog1.FileName) + "\\Temp" + Path.GetFileName(openFileDialog1.FileName)) });
                    }
                    else
                    {
                        uploadResult = await cloud.UploadAsync(new ImageUploadParams { File = new FileDescription(openFileDialog1.FileName) });
                    }
                    imgURI = uploadResult.Uri.AbsoluteUri;
                    if (imageFlipped)
                    {
                        File.Delete(Path.GetDirectoryName(openFileDialog1.FileName) + "\\Temp" + Path.GetFileName(openFileDialog1.FileName));
                    }
                    imageFlipped = false;
                }
                catch
                {
                    imageFlipped = false;
                    MessageBox.Show("Error in Uploading The Image.");
                    lblPath.Text    = "";
                    button1.Enabled = true;
                    // button2.Enabled = true;
                    richTextBox1.Text = "Image Content Here.";
                    return;
                }

                pictureBox1.Image = bmp;
                richTextBox1.Text = "Status: Processing...";
                new Thread(() =>
                {
                    var r      = FacePlusPlus.recongnizeWithURL(imgURI);
                    int apiNum = Decider.decideCategoryAPI(Application.ExecutablePath);
                    switch (apiNum)
                    {
                    case 1:
                        var a = Alchemy.recongnizeWithURL(imgURI);
                        showResult(r, a);
                        break;

                    case 2:
                        var re = Rekognize.recongnizeWithURL(imgURI);
                        showResult(r, re);
                        break;

                    case 3:
                        var v = Vision.recongnizeWithURL(imgURI);
                        showResult(r, v);
                        break;

                    default:
                        MessageBox.Show("Please Try Again");
                        break;
                    }
                    DelResParams delPar = new DelResParams();
                    delPar.PublicIds.Add(uploadResult.PublicId);
                    cloud.DeleteResources(delPar);
                    this.Invoke(new Action(() =>
                    {
                        button1.Enabled = true;
                        // button2.Enabled = true;
                    }));
                }).Start();
            }
        }
コード例 #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (Uri.IsWellFormedUriString(textBox1.Text, UriKind.Absolute))
            {
                richTextBox1.Clear();
                richTextBox1.Focus();
                richTextBox1.Text = "Status: Processing...";
                button1.Enabled   = false;
                button2.Enabled   = false;
                WebClient client = new WebClient();
                try
                {
                    new Thread(() =>
                    {
                        byte[] imgbyte    = client.DownloadData(new Uri(textBox1.Text));
                        MemoryStream ms   = new MemoryStream(imgbyte);
                        pictureBox1.Image = Bitmap.FromStream(ms);
                        Alchemy.recongnizeWithURL(textBox1.Text);
                        var r      = FacePlusPlus.recongnizeWithURL(textBox1.Text);
                        int apiNum = Decider.decideCategoryAPI(Application.ExecutablePath);
                        switch (apiNum)
                        {
                        case 1:
                            var a = Alchemy.recongnizeWithURL(textBox1.Text);
                            showResult(r, a);
                            break;

                        case 2:
                            var re = Rekognize.recongnizeWithURL(textBox1.Text);
                            showResult(r, re);
                            break;

                        case 3:
                            var v = Vision.recongnizeWithURL(textBox1.Text);
                            showResult(r, v);
                            break;

                        default:
                            MessageBox.Show("Please Try Again");
                            break;
                        }
                        this.Invoke(new Action(() =>
                        {
                            button1.Enabled = true;
                            //  button2.Enabled = true;
                        }));
                        textBox1.Text = "Paste Image URL Here";
                    }).Start();
                }
                catch
                {
                    textBox1.Text     = "Paste Image URL Here";
                    richTextBox1.Text = "Image Content Here.";
                    button1.Enabled   = true;
                    // button2.Enabled = true;
                    MessageBox.Show("Unsupported File Type");
                }
            }
            else
            {
                MessageBox.Show("Incorrect Url");
                button2.Enabled = false;
            }
        }
コード例 #3
0
        public Form1()
        {
            //TODO:Register App in Windows Registry
            if (Registry.GetValue(@"HKEY_CLASSES_ROOT\*\shell\Read Image Content\command", "", null) == null)
            {
                try
                {
                    var key = Registry.ClassesRoot.OpenSubKey("*").OpenSubKey("shell", true);
                    key = key.CreateSubKey("Read Image Content");
                    key = key.CreateSubKey("command");
                    key.SetValue("", Application.ExecutablePath + " \"%1\"");
                }
                catch
                {
                    MessageBox.Show("Open The App As Administrator\nWe just need it for the first run.", "Notification", MessageBoxButtons.OK);
                    Environment.Exit(Environment.ExitCode);
                }
            }
            InitializeComponent();
            toolTip1.SetToolTip(textBox1, "URL");
            pictureBox1.SizeMode     = PictureBoxSizeMode.StretchImage;
            openFileDialog1.FileName = "";
            openFileDialog1.Filter   = "JPEG Image(*.jpg)|*.jpg|BMP Image(*.bmp)|*.bmp|PNG Image(*.png)|*.png|GIF Image(*.gif)|*.gif";
            //TODO: Check if the app was opened from Context Menu. If True We'll get the file path and process this file.
            string[] args = Environment.GetCommandLineArgs();
            GrantAccess(Path.GetDirectoryName(args[0]) + "\\lastUsed.ep");
            if (args.Count() > 1)
            {
                if (args[1].ToLower().Contains(".jpg") || args[1].ToLower().Contains(".bmp") || args[1].ToLower().Contains(".png") || args[1].ToLower().Contains(".gif"))
                {
                    richTextBox1.Clear();
                    richTextBox1.Text = "Status: Uploading...";
                    lblPath.Text      = args[1];
                    button1.Enabled   = false;
                    button2.Enabled   = false;
                    Bitmap bmp          = new Bitmap(args[1]);
                    bool   imageFlipped = false;
                    foreach (var p in bmp.PropertyItems)
                    {
                        if (p.Id == 274)
                        {
                            var Orientation = (int)p.Value[0];
                            if (Orientation == 6)
                            {
                                bmp.RotateFlip(RotateFlipType.Rotate90FlipNone);
                                imageFlipped = true;
                            }
                            if (Orientation == 7)
                            {
                                bmp.RotateFlip(RotateFlipType.Rotate180FlipNone);
                                imageFlipped = true;
                            }
                            if (Orientation == 8)
                            {
                                bmp.RotateFlip(RotateFlipType.Rotate270FlipNone);
                                imageFlipped = true;
                            }
                            break;
                        }
                    }
                    try
                    {
                        if (imageFlipped)
                        {
                            if (Path.GetFileName(args[1]).ToLower().EndsWith(".jpg"))
                            {
                                bmp.Save(Path.GetDirectoryName(args[1]) + "\\Temp" + Path.GetFileName(args[1]), System.Drawing.Imaging.ImageFormat.Jpeg);
                            }
                            else if (Path.GetFileName(args[1]).ToLower().EndsWith(".png"))
                            {
                                bmp.Save(Path.GetDirectoryName(args[1]) + "\\Temp" + Path.GetFileName(args[1]), System.Drawing.Imaging.ImageFormat.Png);
                            }
                            else if (Path.GetFileName(args[1]).ToLower().EndsWith(".gif"))
                            {
                                bmp.Save(Path.GetDirectoryName(args[1]) + "\\Temp" + Path.GetFileName(args[1]), System.Drawing.Imaging.ImageFormat.Gif);
                            }
                            else if (Path.GetFileName(args[1]).ToLower().EndsWith(".bmp"))
                            {
                                bmp.Save(Path.GetDirectoryName(args[1]) + "\\Temp" + Path.GetFileName(args[1]), System.Drawing.Imaging.ImageFormat.Bmp);
                            }
                        }
                    }
                    catch (Exception ex) { MessageBox.Show(ex.ToString()); }
                    Account    acc          = new Account("eyepower", "<API_KEY>", "<API_SECRET>");
                    Cloudinary cloud        = new Cloudinary(acc);
                    var        uploadResult = new ImageUploadResult();
                    string     imgURI       = "";
                    new Thread(() =>
                    {
                        try
                        {
                            if (imageFlipped)
                            {
                                uploadResult = cloud.Upload(new ImageUploadParams {
                                    File = new FileDescription(Path.GetDirectoryName(args[1]) + "\\Temp" + Path.GetFileName(args[1]))
                                });
                            }
                            else
                            {
                                uploadResult = cloud.Upload(new ImageUploadParams {
                                    File = new FileDescription(args[1])
                                });
                            }
                            imgURI = uploadResult.Uri.AbsoluteUri;
                            if (imageFlipped)
                            {
                                File.Delete(Path.GetDirectoryName(args[1]) + "\\Temp" + Path.GetFileName(args[1]));
                            }
                            imageFlipped = false;
                        }
                        catch
                        {
                            imageFlipped = false;
                            MessageBox.Show("Error in Uploading The Image.");
                            lblPath.Text    = "";
                            button1.Enabled = true;
                            // button2.Enabled = true;
                            richTextBox1.Text = "Image Content Here.";
                            return;
                        }

                        pictureBox1.Image = bmp;
                        richTextBox1.Text = "Status: Processing...";

                        try
                        {
                            var r      = FacePlusPlus.recongnizeWithURL(imgURI);
                            int apiNum = Decider.decideCategoryAPI(Application.ExecutablePath);
                            switch (apiNum)
                            {
                            case 1:
                                var a = Alchemy.recongnizeWithURL(imgURI);
                                showResult(r, a);
                                break;

                            case 2:
                                var re = Rekognize.recongnizeWithURL(imgURI);
                                showResult(r, re);
                                break;

                            case 3:
                                var v = Vision.recongnizeWithURL(imgURI);
                                showResult(r, v);
                                break;

                            default:
                                MessageBox.Show("Please Try Again");
                                break;
                            }
                            DelResParams delPar = new DelResParams();
                            delPar.PublicIds.Add(uploadResult.PublicId);
                            cloud.DeleteResources(delPar);
                            this.Invoke(new Action(() =>
                            {
                                button1.Enabled = true;
                                // button2.Enabled = true;
                            }));
                        }
                        catch (Exception ex) { MessageBox.Show(ex.ToString()); }
                    }).Start();
                }
                else
                {
                    MessageBox.Show("Unsupported File Type");
                    Environment.Exit(Environment.ExitCode);
                }
            }
        }