Пример #1
0
        private void button_GetScreenShort_Click(object sender, EventArgs e)
        {
            int x = 0, y = 0, width = 2, height = 2;

            try
            {
                x      = int.Parse(textBox_X.Text);
                y      = int.Parse(textBox_Y.Text);
                width  = int.Parse(textBox_Width.Text);
                height = int.Parse(textBox_Height.Text);
            }
            catch
            {
                MessageBox.Show("截图信息格式不正确,必须为数字");
                return;
            }

            byte[] screenShot;
            try
            {
                if (checkBox_PCScreen.Checked)
                {
                    screenShot = BitmapOperation.CutScreen(new Point(x, y), new Size(width, height));
                }
                else
                {
                    if (!ADB.CheckConnect())
                    {
                        label_ConnectStatus.Text      = "未连接";
                        label_ConnectStatus.ForeColor = Color.Red;
                        MessageBox.Show("连接手机失败,请按照步骤1配置!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    string screenShotPath = ADB.GetScreenshotPath();
                    screenShot = BitmapOperation.CutImage(screenShotPath, new Point(x, y), new Size(width, height));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("图像信息错误,请检查图片大小是否超出设备分辨率\r\n\r\n详细信息:\r\n" + ex, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }


            MemoryStream memoryStream = new MemoryStream(screenShot);

            pictureBox_ScreenShot.Image = Image.FromStream(memoryStream);
            memoryStream.Close();
        }
Пример #2
0
        private void button_GetArea_Click(object sender, EventArgs e)
        {
            Image screenShot;

            try
            {
                if (checkBox_PCScreen.Checked)
                {
                    byte[] temp = BitmapOperation.CutScreen(new Point(0, 0), Screen.AllScreens[0].Bounds.Size);
                    screenShot = Image.FromStream(new MemoryStream(temp));
                }
                else
                {
                    if (!ADB.CheckConnect())
                    {
                        label_ConnectStatus.Text      = "未连接";
                        label_ConnectStatus.ForeColor = Color.Red;
                        MessageBox.Show("连接手机失败,请按照步骤1配置!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    byte[] temp = ADB.GetScreenshot();
                    screenShot = Image.FromStream(new MemoryStream(temp));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("图像信息错误,请检查是否连接成功\r\n\r\n详细信息:\r\n" + ex, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            SelectScreenAreaForm selectScreenAreaForm = new SelectScreenAreaForm(screenShot);

            selectScreenAreaForm.SetArea += new SelectScreenAreaForm.SetAreaHandel(SetCutScreenArea);
            selectScreenAreaForm.Show();
            selectScreenAreaForm.Focus();
            this.Hide();
        }
Пример #3
0
        private void SolveProblem()//答题
        {
            if (!checkBox_InPutProblem.Checked)
            {
                label_Message.Text      = "正在获取手机界面";
                label_Message.ForeColor = Color.Orange;
                //获取屏幕截图
                string screenShotPath;
                byte[] smallScreenShot;
                try
                {
                    if (Config.UseEmulator)//是否为模拟器
                    {
                        smallScreenShot = BitmapOperation.CutScreen(new Point(Config.CutX, Config.CutY), new Size(Config.CutWidth, Config.CutHeight));
                    }
                    else
                    {
                        screenShotPath  = ADB.GetScreenshotPath();
                        smallScreenShot = BitmapOperation.CutImage(screenShotPath, new Point(Config.CutX, Config.CutY), new Size(Config.CutWidth, Config.CutHeight));
                        System.IO.File.Delete(screenShotPath);
                    }
                }
                catch (Exception ex)
                {
                    throw new ADBException("获取的屏幕截图无效!" + ex);
                }

                label_Message.Text = "正在识别题目信息";
                //调用API识别文字
                string recognizeResult = BaiDuOCR.Recognize(smallScreenShot);

                string[] recRes = Regex.Split(recognizeResult, "\r\n|\r|\n");
                //检查识别结果正确性
                CheckOCRResult(recRes);
                //显示识别结果

                int notEmptyIndex = recRes.Length - 1;
                while (String.IsNullOrEmpty(recRes[notEmptyIndex]))//忽略空行
                {
                    notEmptyIndex--;
                }

                textBox_AnswerC.Text = AnalyzeProblem.RemoveABC(recRes[notEmptyIndex--]);
                textBox_AnswerB.Text = AnalyzeProblem.RemoveABC(recRes[notEmptyIndex--]);
                textBox_AnswerA.Text = AnalyzeProblem.RemoveABC(recRes[notEmptyIndex--]);

                string problem = recRes[0];

                int dotP = problem.IndexOf('.');
                if (dotP != -1)
                {
                    problem = problem.Substring(dotP + 1, problem.Length - dotP - 1);
                }

                for (int i = 1; i <= notEmptyIndex; i++)
                {
                    problem += recRes[i];
                }

                textBox_Problem.Text = problem;
            }

            //浏览器跳转到搜索页面

            if (Config.RemoveUselessInfo)//移除无用信息
            {
                browserForm.Jump("http://www.baidu.com/s?wd=" + SearchEngine.UrlEncode(AnalyzeProblem.RemoveUselessInfo(textBox_Problem.Text)));
            }
            else
            {
                browserForm.Jump("http://www.baidu.com/s?wd=" + SearchEngine.UrlEncode(textBox_Problem.Text));
            }

            browserForm.Show();
            browserForm.WindowState = FormWindowState.Normal;

            label_Message.Text = "正在分析题目";
            //分析问题
            string[]      answerArr = new string[] { textBox_AnswerA.Text, textBox_AnswerB.Text, textBox_AnswerC.Text };
            AnalyzeResult aRes      = AnalyzeProblem.Analyze(textBox_Problem.Text, answerArr);

            char[] ans = new char[3] {
                'A', 'B', 'C'
            };
            label_Message.Text = "最有可能选择:" + ans[aRes.Index] + "项!" + answerArr[aRes.Index];
            if (aRes.Oppose)
            {
                label_Message.Text += "(包含否定词)";
            }

            label_Message.ForeColor   = Color.Green;
            label_AnalyzeA.ForeColor  = Color.DarkGreen;
            label_AnalyzeB.ForeColor  = Color.DarkGreen;
            label_AnalyzeC.ForeColor  = Color.DarkGreen;
            textBox_AnswerA.ForeColor = Color.Black;
            textBox_AnswerB.ForeColor = Color.Black;
            textBox_AnswerC.ForeColor = Color.Black;

            switch (aRes.Index)
            {
            case 0: label_AnalyzeA.ForeColor = Color.Red;
                textBox_AnswerA.ForeColor    = Color.Red;
                break;

            case 1: label_AnalyzeB.ForeColor = Color.Red;
                textBox_AnswerB.ForeColor    = Color.Red;
                break;

            case 2: label_AnalyzeC.ForeColor = Color.Red;
                textBox_AnswerC.ForeColor    = Color.Red;
                break;
            }

            //显示概率
            label_AnalyzeA.Text = "概率:" + aRes.Probability[0].ToString() + "%";
            label_AnalyzeB.Text = "概率:" + aRes.Probability[1].ToString() + "%";
            label_AnalyzeC.Text = "概率:" + aRes.Probability[2].ToString() + "%";
        }